Trigger one flow from multiple SharePoint lists

This post was inspired by a situation I faced at one of my customers. I was migrating SharePoint 2010 to SharePoint Online and in one site customer had many lists, where users were able to create items. Every time someone created or updated an item, SharePoint Designer workflow was sending them confirmation e-mail. Case was, that the lists were using the same workflow simply replicated per list.

Of course, I could simply create multiple flows doing the same job, but then I thought, this is just a matter of time customer would need to change something in the logic of flow, so I would then need to update {n} workflows. Plus, I love optimizing whatever is possible. So my idea was to simply find a way to create one flow, that could be triggered from multiple SharePoint lists.

After a short research I found this Twitter thread from John Liu:

And just moment later, his awesome post describing how this goal can be accomplished by using SharePoint lists webhooks and subscribing Power Automate flow to them:

The general idea is to create two flows:

  1. Subscriber: Triggered on a schedule, that checks if Handler flow is subscribed to specific list webhook and if not – subscribes it.
  2. Handler: Triggered via HTTP request, that is subscribed to list’s webhook and that is triggered whenever a change happens on that list.

How it works

Important! The whole solution requires Power Automate premium license, because Handler flow is triggered using premium action. The more users will use the solution, the more consider using “per flow” subscription instead of “per user”, as the whole solution might be considered as company-wide.

Basically what John described works like a charm, although I was missing very much a piece, that would help me to precisely get the items which were actually created/ modified when the Handler flow is triggered, but after it was triggered before. The point is, webhook only sends information, that event occurred on the specific list, but doesn’t send eg. list of items’ IDs, that were affected. For that John suggested, to simply get all items modified in last 10 seconds. This was not the best idea, since sometimes Handler flow was triggered after eg. 2 minutes. Then John provided link to Leo Siddle‘s post, where he describes in details how to use Folder.GetListItemChanges endpoint and Change tokens:

To me it was a bit too complex and I was looking for something a bit easier.

How I did it?

How to actually trigger one flow from multiple SharePoint lists? It’s easier as you may think!

Subscriber flow

First the Subscriber flow. What I changed was that I also defined which lists should be monitored and should have the Handler subscribed to their webhooks. To do that, I defined a piece of odata query, to get only lists with specific guids:

and (Id eq guid'ec080920-5d86-4739-a14f-34298bcebfc7' or Id eq guid'a6ffb3c0-6b5c-4eb8-b4db-6b477f619485' or Id eq guid'f2d3252c-d00f-4da8-aabd-f2dd96029780' or ....)

Then I used “Send an HTTP Request to SharePoint” action, to get details of the lists I want to monitor:

_api/web/lists?$filter=BaseType eq 0 and Hidden eq false and (Id eq .... )

Note! BaseType eq 0 means lists.

Then I used filter action to get lists IDs (John used Titles, I think IDs are more secure) and finally for each ID I generated URL to call list’s Subscriptions endpoint:

Next, for each Subscription link, first I am getting its details like John did, then getting its ‘clientState’ value and then I am also getting the ‘resourceId’ – so the current list guid, to later use it as a value for “resource” parameter when registering new webhook:

  1. This is the current list’s GUID extracted by the ‘Compose’ action above.
  2. This is URL of the Handler flow, copied from its trigger action.
  3. This is information, how long should be the subscription valid. I am setting it for 30 days. After that, it will be unsubscribed.
  4. This is guid of the Subscriber flow, that is used to check, if for given list subscription done by the flow is present. You can get it by using the workflow()?['name'] expression.

Handler flow

Flow is triggered using the “When a HTTP request is received” action. Next steps are the same as John described in his second post: and they are really good explained.

Now this is where I put in my two cents. Instead of getting all items from specific list modified in last 10 seconds OR following complex solution described by Leo, I decided to use just a SharePoint list, since the whole solution is for SharePoint anyway. My list is built from the following columns:

  1. Title – name of the list being monitored.
  2. GUID – guid of the list being monitored.
  3. LastModificationDateTime – timestamp when last time something on the list was changed. For the first run I set it to current date and time.

Next in my Handler flow, I am querying that list to get LastModificationDateTime for list which triggered the flow (using GUID as filter) and then I am updating the last modification date to the current datetime:

What I am next doing is getting a list of all items that were modified between the previous “LastModificationDateTime” moment and current datetime. And lastly, for each such item I am executing those steps, there were common for all workflows I found in all SharePoint 2010 site before it was migrated:

This works like a charm! I highly recommend you this way of handling situations, that you have multiple lists/ libraries even in different sites, that are using exactly the same workflows. Instead of renaming and copying existing flow per each list, simply follow the Subscriber – Handler approach. It’s much more elegant and way easier for maintenance and development.

Let me know what you think and if you find it useful in the comments below. Thanks!

Tomasz Poszytek

Hi, I am Tomasz. I am expert in the field of process automation and business solutions' building using Power Platform. I am Microsoft MVP and Nintex vTE.

  • Darshana T

    Thank for the great solution.
    I have gone through the john blog.
    Part I- Webhook Subcription is done. for second part I have run into a problem which is that when I am uploading file the webhook fails to fire, I have tried to upload a document 4 to 5 times, but flow fails not triggered..
    Do you know why this is happening?
    I hope you guide me in the right direction.

    October 10, 2021 at 3:00 pm Reply
    • Tomasz Poszytek

      Yeah, I was facing that either. My solution was to re-add the webhook, but first to remove all existing webhooks. Also, in my scenarios webhooks are refreshed every 5 days.

      October 26, 2021 at 11:07 pm Reply
      • sana

        hy i need help i want to update user profile using powerapps please reply if you can

        November 28, 2022 at 7:35 am Reply

    Great article! I followed your steps to build two flows.

    However, I got stuck at posting subscription. I used the handlerflow post url as the notification URL but when I post to subscribe, kept getting error that Failed to validate the notification URL:

    The POST URI is: _api/web/lists(‘{listguid}’)/Subscriptions

    Hope you can guide me to resolve those issues, thanks a lot!

    May 18, 2022 at 6:36 pm Reply
    • Tomasz Poszytek

      Gosh, difficult to say. It all seems correct to me. However that handler flow URI you’re not obtaining from the POST request to subscriptions, it’s just a URI of another cloud flow that will be called anytime there’s an event fired on the list, via webhook. You might want to lookup John Liu’s explanation on that part, since I didn’t want to copy his work.

      May 19, 2022 at 9:11 am Reply
    • Luis Filipe Nunes

      Gosh … I managed to get my work done after 4 hours of troubleshoot … I was facing the same error “Failed to validate the notification URL” .. Solution: On your Event Handler Flow you should have a HTTP RESPONSE ACTION in the end of the Flow that will be of type “Content-Type” “text/plan” and that will have “triggerOutputs()?[‘queries’]?[‘validationtoken’]” as the body/value since without it the SharePoint can’t subscribe your Event Handler.

      June 28, 2022 at 5:42 pm Reply
  • Han

    Hi there. Thanks for sharing the flow. Is it possible for you to include the screenshot of the both flows in full view? Thanks in advance once again!

    November 15, 2022 at 6:22 am Reply
    • Tomasz Poszytek

      I understand, you would like to see how both flows were built, but that I cannot do.

      December 14, 2022 at 10:19 am Reply

Post a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.