Saturday, September 22, 2018

Triggering a single Flow from multiple SharePoint Lists or Libraries

One of the many great uses for Flow is to perform certain actions when an item is added to a SharePoint List or Library.  This is easy to achieve using the When a File is created or When an Item is created triggers.


However, what if you want to run the same Flow for triggers generated from multiple lists?  One option is to have one flow per list that will call the common flow.  Doable, but requires a lot of extra work and maintenance if the logic changes in any way.  What would simplify this process is an event that is easy to set up and configure on any list and library.

Using an Email-based trigger

In this example, I'm leveraging the Alerts mechanism that can be set up on each list or library to trigger a common flow.  The logic behind this approach is that when SharePoint sends an alert email on an item or document, it includes a link to the item and item ID, which are the key pieces of information you need.

Preconditions

To do so requires several things:

  1. Alert emails should be sent immediately
  2. Ideally, there should be a service account for all the flows
  3. The Alert Title needs to be consistent across all the lists for the flow


Flow breakdown

The Flow, depicted below, is broken down into 8 steps.


The first step is the trigger, which acts when an email arrives for the user account that is running the Flow.  Alert emails are generated from the no-reply@sharepointonline.com system account, so you can configure the trigger to only act on messages coming from that address.  Also, make sure to configure the Subject Filter to match the Alert Title you set on your list.

Steps 2 through 6 are mostly a text parsing exercise to extract the site URL, list URL, and item ID.  They are all embedded in the email body.  Step 3 helps clean up all the HTML tags, thus making it a bit easier to parse out the elements.

Once you have your item ID and link, you're all set to get the item (step 7) and do with it as you wish.  Optionally in step 8, you can delete the alert email if you have no other use for it.

0 comments:

Post a Comment