cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Mushwar
Regular Visitor

A laymans solution to infinate loop problem with ''When an Item is Created or Modified''

Hi all, I'm writing this comment after succesfully stopped a loop in ''When an item is created of modified''. As I'm a newbie to Flow this took a lot of time to get the logic correct. I hope that this comment might help others, so let's go.

 

TLDR; Write Trigger Conditions for the ''When an item is created or modified'' and add these blockers with ''Update Item''. You can create hidden colums for the list if you need more blocker data.

 

Background: When a new item is added to a list or an existing item is modified, an email needs to be sent and the item gets new meta data. Ok, doens't sound that difficult? Well..

 

Paradox: The new meta data will trigger the flow once again, causing a loop, this we know.

 

Case triggers: for this particular flow the triggers are: ''Delivery date < today & Send = true & OrderID = false'' we identified that the trigger ''delivery date < today'' where the cause of the loop, the other two triggers we could block with new meta data on the item.

 

Solution: in the settings for ''When an item is created of modified'' you have options to set Trigger Conditions, after some testing we  could determinate that each row of Trigger Conditions where ''AND'', not ''OR''. Therefore the ''OR'' needed to be in the same row, here's our 1st condition:

 

@or(or(lessOrEquals(triggerBody()?['Svea_Order_Date'], utcNow()), equals(triggerBody()?['Send'], true)), equals(triggerBody()?['Order_ID'], ''))

 

 

 Ok, we've now blocked 2/3 of the triggers, the date < today still causes a loop. This got solved by utilizing the ''AND'' relationships between the rows of the Trigger Conditions. This is the condition:

 

@equals(triggerBody()?['Skickad'], false)

 

 

Though our list didn't have a metadata showing if an email has been sent or not, so we created a hidden column called ''Sent = YES/NO'' with ''NO'' being the standard value. With this we can update our metadata to YES and therefore blocking all triggers when the item is modified.

 

The end result of the trigger conditions looks like this.

 

@or(or(lessOrEquals(triggerBody()?['Svea_Order_Datum'], utcNow()), equals(triggerBody()?['Skicka'], true)), equals(triggerBody()?['Order_ID'], ''))

 

there's a native ''AND'' relationship between these two rows.

 

@equals(triggerBody()?['Skickad'], false)

 

 

 

 

 

 

 

 

 

Can't figure out how to add pictures to this post.. sorry..

 

Helpful resources

Announcements
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Automate Community!

firstImage

Now Live: Power Virtual Agents Community!

We are excited to announce the launch of Power Virtual Agents Community. Check it out now!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Users online (5,723)