Do-Until not working as expected
-
08-02-2021 - |
Question
I have a very simple scenario where in my flow will be triggered when a new item is created on a list by someone. First step is it sends an email to the manager, where he'll reviw the request and fills a field called 'Assigned To'. Once this is done, the 'Assigned To' person will get an email, and he'll take it further. So basically, the task has to wait until the manager assigns the name. This field is a "Person" field, so it will have display name, email, etc.
First, within a do-until loop, i'm checking if the 'Assigned To' is not null, then wait for some time, and again check until it is not null, then proceed. It's not working. THen I thought may be its checking for object, so i was checking on 'Assinged To Email'. Even in this case, it is not working. It was continuously looping forever - even when the manager assigns a value. THen, a very bad appraoch, i created a temporary variable, and assigned the value to it when email is filled out. Even then its not working. For debugging, i setup a mail activity within the loop to see what is the value being set, and its always empty(null)
Where am I going wrong? thanks
La solution
So, if you are referencing a value from the Flow Trigger inside your Flow, that value will not change until the next time the Flow runs. If you hover over one of your references, you will see that the expression it is using is something like triggerBody()?['MyAssignedToField']
-- the values from the triggerBody
do not change during the course of the Flow. The values that Triggered your Flow will stay that way for the duration of your Flow, even if someone changes the source Item while the Flow is running. If you want to pick up changes while your flow is running, then you have to tell it to do that.
Immediately before your Do..Until
action, initialize a variable named something like currentAssignedTo
as an object and set it's initial value equal to null
. Change your Do..until
condition to run until currentAssignedTo
is not equal to
null
. Immediately after your Delay
action, insert a SharePoint Get Item
action, to get same item that initially triggered your Flow (ID = trigger ID). Then insert an action to set your currentAssignedTo
variable equal to the AssignedTo column from the item you just got. See screenshot of mocked up Flow: