How to use a list column value as a flag to resolve infinite loop problems in a Power Automate flow? - sharepoint-online

I am trying to resolve this error in Power Automate:
Actions in this flow may result in an infinite trigger loop.
Please ensure you add appropriate conditional checks to prevent this flow from triggering itself.
This seems to be a common problem when using this trigger:
When an item is created or modified
where the associated flow contains this action:
Update item
The dynamic is succinctly explained in these videos here and here.
Desired Behaviour
The desired behaviour is that the flow:
Runs when a list item is created or modified by a user (and updates the item accordingly)
But not when the flow itself updates the item
Actual Behaviour
The actual behaviour is that the flow:
Runs when a list item is created or modified by a user (and updates the item accordingly)
Also runs when the flow itself updates the item (causing an infinite loop)
What I've Tried
Some posts suggest using a Service Account to run the flow and then apply the logic:
If the flow was triggered by a Service Account, terminate the flow
But I do not have access to a service account in this scenario.  
The simplest solution seems to be answers like this one and this one.
They suggest creating a column in the SharePoint List to store a 'flag'.  
I understand the concept of using flags to indicate:
DO run the flow if SOME_FLAG is false
DO NOT run the flow if SOME_FLAG is true
But I am having trouble when it comes to implementing them properly in this scenario. 
Specifically, I have added a Yes/No column to my List called LastModifedByFlow.  
The default value is No (i.e. false).
My flow is structured like this:
01)  TRIGGER:  When an item is created or modified
02)  I have added this Trigger Condition
#equals(triggerBody()?['LastModifiedByFlow'],false)
03)  This means the flow will run when LastModifiedByFlow is false
04)  Create some variables  
05)  ACTION: Update the item - this includes setting the LastModifedByFlow value to true
Question
The first time the flow runs, it works great:
the item is updated
the item's LastModifedByFlow value is set to true so the flow doesn't run again
But how and where in the flow do I set the LastModifedByFlow value back to false?
So that the flow will run each time a user subsequently modifies the list item?
  

It is recommended that you set a default value of “Yes” for the Yes/No column first. When the item is created, the flow will be triggered. After the flow is completed, the value of the column "Yes" will become "No". When the item is modified, it is recommended to manually change "No" to "Yes" to trigger the flow. Here is a post for your reference.

Related

update status value in sharepoint list using power automate

I have two fields named as Status and Approved.
In my form when approver selects the option either approved or reject, the result will get save in the approved field.
Now I want to change the status field also as per the result save in the approved field to Approved or Rejected.
I tried this by using update item action in power automate flow and it is not working. It is calling the same thing in a loop. It is also showing warning that this action will trigger an infinite loop.
Can anyone please suggest me any solution with this action in flow.
You can add trigger conditions to your flow so that it will only fire when a specific set of conditions are met.
This is a basic example that you can try and incorporate into your own flow.
My list has two specific fields, Field1 and Field2. As per your trigger, when an item is created or modified, I only want to trigger the flow when those two fields are not equal and if they're not, the flow will update Field2 with the value from Field1.
This removes the recursive nature of the flow as it will do the check prior to actually executing.
My expression for the trigger is shown below ...
... and that setting can be found in the settings of the trigger ...

'When an item is created or modified' trigger not firing until manually saved

I'm running into an odd issue where my Flow will not trigger correctly upon modifying a list item. I have flow set up to copy appended Col1 content to Col2 which can then be listed as an 'updated comment' in my list's default view.
It's the same logic as a SP2013 workflow I've been using, but for whatever reason the flow will not automatically trigger when an item is created/modified in my list - it will only trigger if I go back into the flow and manually save it (the Flow) again. Additionally, if I manually save the Flow a second time, it wipes Col2's existing content.
I am not intimately familiar with any quirks found in the 'When an item is created or modified' SharePoint trigger in Flow, but it's possible I'm missing something obvious.
Below is the logic I'm using.
'Comment Update' MS Flow example
Any help would be much appreciated, I haven't been able to find any posts going over this Flow trigger specifically. It seems like there would either be a very obvious solution to this, or this is a glaring bug with Flow.
Thank you for your time.

Microsoft Flow Execution Order

I have created a bunch of short flows that act on a single SharePoint list item to reduce complexity, but I've run into a problem with the order in which they execute. I think I could best explain this with an example, so please see below:
Let's say there are three flows, SetTitle, SetPermissions, and SendEmail (sends an email based on the new value after a column changes). Ideally, SetPermissions would run first, then SendEmail, and finally SetTitle since it modifies the item. That modification is a problem because it adds a version to Version History, which I am checking in the SendEmail flow to see if the value of a column changed.
Currently, however, SetTitle sometimes runs first, which breaks SendEmail because now the most recently displaced version does not contain a record of the column change that happened two versions ago.
I would like to avoid creating additional columns in the item to track column changes or emails sent, because we're creating these flows to avoid that messy complexity.
I'm hoping that there is some hidden execution order option somewhere, because as I said, I don't really want to create extra columns or trigger flows based on HTTP calls. Of course, what I'm doing now isn't working, so I understand that I may have to compromise.
I do not think what you are looking for is possible tbh.
I know you said you do not want to create more columns, but the only solution that I can think of requires only 1 extra column to be created. Use that to run the flows in the right order.
For example, if there are two flows: f1 and f2, set the default value of the new column(let's call it 'stage') to 0. Then, add a condition to f1 so it only runs when the stage is 0 and also updates the column to 1. Then f2 also has an initial condition check and runs only when 'Stage' is '1' and also sets 'Stage' to '2'.
Hope this helps.

Azure logic app with Condition

I am creating the logic app when I want to send an email when there are duplicate entries created in my database, and until those are not removed email should be triggered after some interval
As per Logic App, we can create a trigger on SQL when data is inserted or modified as bellow
So I selected the first option then I am adding another action which will run my SQL script to check the logic of duplicate entries
and last I have added another action to send an email.
Now I want my last action of sending email to be executed only when my query comes up with some result
You can use a Condition Control to check whether the given result set is valid if the condition satisfies then you can send the email
See my logic app below.
Here I've added the Execute a Stored Procedure Action. My stored procedure returns resultsets, you can use the logic for checking the duplicate and in the next condition you can check the duplicate result is true (or) false. If it's true you can send email else not to.
Update 1
How to Add condition control
I think you're better off programming the duplicate condition detection into a Stored Procedure rather than a SQL Trigger then using the Logic App change Trigger.
Instead, use a Logic App and Recurrence to call the Stored Procedure that queries for duplicates and returns the necessary meta data.
Trigger + table + change will be less reliable then you expect and much harder to maintain.

Whether to use Steps or Conditions within a single step in a SharePoint workflow

I'm creating a workflow that does the following, and I'm looking for guidance on the best practices of splitting up a workflow into conditions and/or steps.
For the Projects list, each time a list item is created or modified, the workflow should run and do the following:
If Status = New, create a couple variables AND send specific email
If Status = Open, send specific email
If Status = Estimated, send specific email
If Status = Approved, send specific email
If Status = Ready, send specific email
If Assigned To is modified, send specific email to the Assigned To person or group.
If Status = Ready, and has been ready for more than 5 days, send specific email.
So for the first 5 items above, it seems to me they could all be separate conditions/actions within a single step.
For the Assigned To item, I think I'll need to have the primary workflow create a record in a new list, which would then trigger a secondary workflow to send the notification email to the Assigned To designee.
And for the Status over 5 days item, should this just be another condition/action under the primary workflow's step 1 or should it be a separate step?
In this scenario, I'm just not seeing any need for separate steps within the primary workflow. Am I missing something? What's the general thinking for when you should use additional steps in workflows, as opposed to just adding conditions?
Thanks!
I think I finally stumbled on the answer to my own question.
From what I can tell, in any step, the workflow will stop once a condition branch evaluates to true. So if more than one action needs to occur before the workflow is started again, then each of those conditions must be in it's own step. You can have a single step with multiple conditions of course, but only one of those conditions can evaluate to true.
Does this sound accurate?

Resources