Flow: Try, Catch on User List Till You Get A Match.

Hi everyone, so "Template Tuesday" has come and gone and what a lovely little offering the Flow Team have packaged up for you. The scope action is one I don't see in use too often, but when you consider it's power it really is one for the watching, and the using! The fundamentals behind Try, Catch, Finally is how it has been dressed up and it works a treat. Have a look at the tweet below and see more details of the template there too.

You will see from above that "Try, Catch and Finally Template" will be triggered by a button, which is great, if you need a button but the same principals can be applied using any trigger and with any task. Just like most things in Microsoft Flow. So here it is in a little more detail.

Earlier this evening, a user on the Flow Community Form had this request:

"When entering or modifying an item in a SharePoint list and assigning a responsible (responsible field filled in item), the Next Step field must be entered in the calendar of the person assigned (Assigned field) on the given day in the (Next Step Data field)."

They wen't on to say …

"So there is a detail, I have an organization with 10 people, and this list is accessible to all. I need that if I put the name of the person x, in the column named (assigned user), the task determined in (Next Step) should go to the calendar only of the determined person x"

Whilst the scope (pardon the pun) of this post is more to demonstrate the power of Try, Catch, Finally and a further workaround may be required in order to get the event into the user's calendar, here goes!

Would you like to buy Alan a coffee?

Visit the AlanPs1 Ko-fi page

So by my logic, this indicates to me that there are a few steps to follow in this process but we have a list to work from so let's start working our way through that list.

  • If the modified list item belonged to User1, create a calendar event for User1.
  • If not, look for User2
  • If the modified list item belonged to User2, create a calendar event for User2.
  • If not look for User 3

and so on to meet the needs of 10 users (or so).

So here is a high level overview of my Flow.

Here is my list.

In my example, I will change the trigger and will start with "When and item is created or modified" from the SharePoint connector. I will then move on to a "Get Items" from the same connector so we get access to each user, or "Assigned User" from the list as the community member had referred to these users as.

The information in this post works and can be applied with any other actions to suit, send email, push notifications, you name it. The version I am publishing here is purely for demonstration and I won't use 10 users, I will only use 2 and I will miss out on the use of "Finally" as "Catch" is enough based on the logic and the specification for the Flow provided.

Below is "Try 1". It looks for a match for "User1" and if no match, moves on to the next step.

Below is "Try 2". It looks for a match for "User2" and if no match, moves on to the next step.

Below is "Catch". We have already looked for "User1", no match. We have looked for "User2", no match, so we "Catch" which terminates the Flow.

When a match is made, a calendar event is created in my calendar in this example. The use of the "Office 365 Groups" connector could come in handy here to "Create event in group calendar" or it could be the case you have each user's email address populated as a connection, as crude as it sounds. You could also make a Graph call to change the calendar or use Graph in it's entirety to create the event in the required user's own calendar. The possibilities are endless with Try, Catch, Finally and the Scope action.

The best option to meet the user's request looks to be using the "Required Attendees" or "Optional Attendees" fields like the below, although this would leave an event in both calendars but this may still meet requirements for the user despite them saying "the calendar only of the determined person x".

Note: If a reader has alternative way of getting a calendar event into another's calendar that isn't plainly obvious to me and is not listed above, please be sure to post it in the comments or tweet me!

Thanks, Alan

Do you need assistance building this Flow?

Visit the Get Help section of the Power Automate Community