Site icon @WonderLaura

Trigger a Flow from Multiple SharePoint Libraries

In this post, I’ll show you a way that a flow can be set up to manually trigger the same from from multiple locations in SharePoint.  Here’s the back story.  I created an approval workflow for a committee’s SharePoint site, for approving meeting minutes.  Then, another committee wanted the same flow, then another and another.  I ended up creating and managing about 6 different flows that did the exact same thing, on multiple SharePoint sites.  This became painful anytime updates / tweaks needed to be made to the logic or verbiage in the flows.  I had to make all the changes six times.  When a seventh committee wanted this flow as well, that’s when I decided to try and build a more efficient way.  Somebody named Mark Boes, who had read my blog, had sent me a random email back in October, saying that after reading my post about how to create a button in a SharePoint list to trigger a flow, he came upon the realization that the ‘For selected item’ action receives the itemURL from where the button was pressed, regardless of the action Site Address.  Thanks Mark!  I thought this scenario would be a good opportunity to try this out.  Here are the steps:

1.  Create a flow, and use the SharePoint trigger For a selected item.

2.  Pick any site and list or library here.  It doesn’t matter what you pick.

3.  We’ll be initializing seven different string variables.  The first one is for the site root, which is the part of the url that comes before the name of your site.  This isn’t dynamic, you’ll be typing your own in here, as the default value.

4.  Initialize a variable for the item URL.  This is buried in the trigger, here’s the syntax to get it.  Note that I’ve typed the formula there in the comments of the action as well, for easy reference.

Note:  The ItemURL itself looks something like this:

You may wonder why, in my formulas, I don’t just look for the _layouts in the URL.  Well, after I first implemented this solution, I noticed that depending on the view that I was in, or how I got to the item, the URL was structured completely differently and did not contain the _layouts.  So unfortunately, it’s not something that you can reliably depend on.  Same goes for the ListId in the URL.  It’s not always there.

5.  The next four variables just need to be initialized, but with no default value.

6.  Initialize one more variable, for the name of the library that the file is in.  In my solution with the committees, it’s easy because it’s just the “Documents” library for all of them.  In the associated video with this blog post, I explain why there isn’t a way to divulge the name of the current list/library just from the ItemURL.

7.  Add a Compose action, and put together the full URL to the current site, using this expression.  Note that I also put the expression in the comments section of my action, for easy reference.

8. Set a variable.  This is where we concatenate the varSiteRoot, from step 3, along with the URL to that specific site.  As I mention in the video, there are probably various ways that these formulas could have been configured to achieve what we need, this just happens to be the way I did it.

9.   Now, we have the url of the site and the name of the library called Documents, which we keep in a variable varDocLibraryName just because it makes it simpler since we’re using it multiple times.  Now it’s time to get the file’s properties.  SharePoint action Get file properties.

10.  We have to get the filename from the file properties in step 9.  Here’s the formula.  If you’re watching the associated video (below), you’ll notice that I showed a much longer way of achieving this, but this formula is really all you need, it’s the simplest way.

11. Next, the approval action can be added.  Who do you want the approval to go to?

When it comes to whom to assign the approval to, this widely varies.

If you would like the person triggering the flow to manually pick an approver right when they trigger the flow, at step 2 above, add an email input.  Use that value in the assigned to box above.

If you would like the approver to be the person who triggered the flow’s manager, then you can use the Get Manager action instead.

If you’d like to use a person from a person column in the library, you’ll have that data from the get file properties action at step 9.  There are many, many potential ways of getting / setting who it needs to be assigned to.

What do you want to happen after the approval?  Of course that also varies.  Send an email, and set the content approval status are two common ones.

Here’s a screenshot of the whole thing

Now, how do we trigger the flow?

In my example, I created a column called Approval.

Check out my post how to create a button in a SharePoint list to trigger a flow for the instructions to create a button in the library to kick off the flow.  In my real-world example, like I mentioned, each committee uses the Documents library on their site, where they keep the meeting minutes, so I just added this button to that Approval column in each library on each committee site.  They all kick off this exact same flow, so no need to create a separate flow for each library.

Here is the full video where I demonstrated this solution on SharePoint Power Hour:

Note: Since I did this demonstrated this yesterday, I’ve actually fine tuned it a bit more as I wrote down the instructions, for example, I added the variable root site instead of manually typing the number of characters and all that.  And the second half where I get the site and group and all that, I’m going to write as a separate blog post.

Exit mobile version