Avoid infinite loops with flow trigger conditions in Power Automate

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this is Reza barati Microsoft business applications MVP in this video we will explore flow trigger conditions trigger conditions allow you to conditionally trigger your flows based on specific scenarios the advantages here is your flow only runs when required and you save API calls what are a P I calls if you go to a KK not MS slash service limits and I will put this link in the description of this video as well as a user who has a valid license related to the power platform you have something called as request limits and these request limits are a limit based on the number of API requests that you make within a 24 hour time span so for example if you have the standard office licenses that include power apps and power automate you have 2,000 API requests per day and what is an API request every step every action every query that you make whether that query takes place in power apps or whether that query takes place in power automate in a day you have a limit and that is called the request allocation limit which is a 24 hour period for you to be within now if you exceed this number consistently then you will get a notification email that you need to buy additional licensing so you can increase your API request level if you've never checked out the this API request limit I highly recommend you to check this link out I will put this link in the description of this video so you need to be aware that you have a limited set of calls again depending upon your license so you need to be extremely diligent in ensuring that you call your flows only and only when required I am triggering my flow when an item is created or modified now within my flow if I am updating the same item ok so let's say I go to SharePoint and I say I want to update the item and I pick update item and I pick my site I pick my list I pick my ID and ID will come from the same idea of my trigger right here right and let's say I update something I update let's say I need to plug in the title of course because it's a mandatory field and my category is IT and let's say I'm update the description to updated text whatever right I am updating the item now if I save this flow and I want to run this because if I do I will run into a terrible scenario and that scenario is known as the race condition so what will happen is the flow will get triggered right and the flow triggers when an item is created or modified this will in turn go ahead and update the item right this will go ahead and update the item now because I'm updating the same item remember the flow is getting triggered whenever any item is added or updated so it will get called again and again and again and again and this will run into an infinite loop until the system automatically times these cases out ok so there is there is logic baked in wherein this will get stopped after a peculiar amount of time but guess what it's not a question of amount of time it's a question of your flow runs you will be wasting on your flow runs right all your API requests will be gone that's because mistakenly you updated the same item or maybe that's your use case you want to update the item right when you are running into problems now how do I solve a scenario like this I will show you two tricks to get around this one trick number one because my flow is running when an item is created or modified right it's an automated flow it triggers automatically based on a condition remember the flow runs in the context of the accounts the connector is associated with so in my scenario if we look at my connection and question right here the connection is related to my account that is Reza's account now let's take a use case wherein I login with a separate user so let me go ahead and log in with user number two okay so here comes user number two right and this is a completely separate user right now who's logged in now many a times what we do is we build flows for automating our purpose processes of course now if within the flow I am i bleeding the same item I will run into the race condition right but my flow is running the context of an account and the account is Reza now typically in scenarios like these I recommend something known as a service account and service account is nothing but a standard account in your office 365 tenant that has a valid license so just like it says Reza it says service as we see whatever you want to call that account as admin or service and whatever that account is and you can use that account for building these kind of business process oriented flows so let's assume that my account is that service account ok Reza's account is that service account in action now how do I get this to work we're in even when I modify the file right through my flow it doesn't run into that race condition and what's that race condition race condition is it will trigger the flow again and again and again and again how do I stop that once again let's look at our expression this time let's write a completely new expression right here when the item gets updated right when the item gets updated in the flow it will get updated with whose account Reza's account because Reza's account is running the flow or my service account is running the flow so if I head back to my expression and if I search for so you go to search for modified by ok you're a search for modified by and let's say I want to plug in I want to check to see if the modified by user was raised or not or my service account or not I can use modified by email right here ok so I'm just going to compare it with my email address right here and this time what I can do is I can go ahead and do an equals operation right here ok and right here I am gonna plug in my email address now my email address we'll just go ahead and copy this ok remember I'm using a service account to run the flow so let's say this is my address I plug this in so give the modifier equals Torres R that is my condition but remember I want to run my flow and the modifier is not Reza so decorate this by the not operator click out my function is valid okay and of course you can go to the next line as well so here's my expression got a copy this head back here go to settings add the condition plug my condition right here decorated with the @ symbol get done all I've done right now is I'm telling the flow not to trigger if the item is modified by Reza ok and resides what resides my service account is the account under which the flow is running ok now I will go ahead and I will see if this flow if the other user comes back in so I'm going to login back with the other user and this time this user goes ahead and let's say creates an item it's called ticket number 4 and let's say I just save this I just created an item and let's say this user goes and modify stick at number one as well so ticket number 1 gets changed the title is keeping it simple right now click on save so this user came in and made two changes typically you will run into erase scenario why because the flow would get triggered in both the cases and go ahead and update the item and that's a problem because updating would reach or the flow waste all your request limits you don't want that to happen now if I head back and if I look at my flow my flow has ran in both the scenarios but if you notice I don't run into a race condition the flow has not really triggered again even though I have updated my item within the flow itself and that is because of the condition that I put in place now if I head back to my the other user and if i refresh my SharePoint list you will notice that the flow has updated because you notice the description says updated text I updated the description through my flow so that's one way of defining defining a trigger condition in which you do not run into the race condition very very important to understand I see this request a lot I want to trigger my flow only when a peculiar column value is updated ok that is a column value has changed so for example let's say I update this item I'm going to change this to testing and I save this my flow should not trigger but if the category column has change - then my flow should trigger so let's say that's my use case I want to only trigger it when this column value changes now one very important thing to notice if you want to handle a scenario like this the key is going to be for you to have some sort of interaction with power apps it could be a standalone app or it could be a SharePoint customized form so I'm going to go ahead and customize my list using power apps and this will go ahead and create a standard three screen app for me this is good enough for the demo purpose if you notice I've gone ahead and customized my form right here's my form here's my data now what I want to do in this scenario is I want to only have my flow run when this value changes what I need hidden column so I'm going to head back to my list and create a column and I'm gonna call this column run the flow okay it's created a column called run the flow and it's of type single line of text and I'm going to go ahead and say okay let me first go and make sure that it's my app is displayed so I'm just changing the theme and I'm gonna see if this and I will go ahead and publish this change and once this change takes effect if I look at data sources I have my tickets list click on refresh so it will refresh the schema for me and I have that column as a hidden column but right here if I go to fields even though that column is hidden which was none flow it's available right here for me so this gets added to the screen right here now the first thing is if you want to make changes to this you have to unlock this I will go ahead and unlock this now when the user edits the form then I want my scenario to be a little different so what do I do in that case for my main column which is run the flow right I will look at the default value of this card and what I want to do is I want to set the default value of this car - yes or no depending on whether or not the category column has changed this value or not and of course the user can only change the value the user is an edit mode so the first thing I'm going to do is I'm going to check to see if this form is an edit mode so if SharePoint forum one don't display mode is display mode not edit if it is an edit mode so let's say in that case I will say yes to running the workflow otherwise I will say no okay that means right now as you can see I've edited this form I'm doing it in edit mode so it tells me that yes yes you know it the workflow is going to run but I want to walk float around only if this category value changes now in order for me to do that what I need to do is I need to go ahead and figure out there is this value first of all coming from so if I pick this entire card you notice the entire card is selected if I go to advanced if I search for default this value is coming from this item dot category so this holds the current value of the item before saving however when the user makes a change he makes a change right here so if I select this drop down in my case it could be a text in your case it could be a date column whatever your use cases in my case is this data card value so I'm going to copy this head over right here and change the scenario to and this data covered value dot selected dot value because in my case it's a choice field right this is not equal to this item dot this item dot category because that's the name of the column not a value now why'd this item dot category once again because that's the default value of my data card that is coming from my data source but when I'm comparing it to data card value dot selected add value that is the live value that is changing here and just to make sure that what I am saying is correct if you notice right here it says no run the flow is showing us no that means the value has not changed which is true and if I play this app and if I change this to security this changes to yes if I change back to IT it changes to no that's exactly what I want now I will go ahead and save this and I do not need to show this data card of course so I will go ahead and change the visibility of the stefan's so that's the trick create a column hide the column you don't need versioning for this by the ways just create the column hide the column okay go to your card modify the card and write this logic and I have gone ahead and published my app now I'm back in power apps back in SharePoint so I'm going to go ahead and clear up all my items head over to compose I will go ahead and write my condition so my condition right here is going to be so search for run the flow dynamic contact and equals so run the flow equals yes I want to run this flow only when this condition is true so copy this go ahead put it in your trigger condition now your flow will only and only run when that item or that category column is updated otherwise it will not run and let's look at this in action okay this time I don't need the compose action right here so I'm going to delete this can keep it if I want and I am updating the item as well right here now I can even use it in a scenario like this when I do not want to run the flow when I'm updating guide I don't want the race condition well I can just write no over here easy very very simple right now I can go ahead and click on save now it says there's an error that's because I forgot to add the at symbol let me add the add symbol right here click on done click on flow checker no errors let's click on save now if I head back to my flow let's say I create a new ticket okay I call this ticket one I'm going to click on save let's create another one called ticket to now input the conditions notice around the flow is no now why is run the flow no because when this item got created in that expression that I wrote that logic that I wrote it's setting it as no now if you wanted to set as a set it as yes if a new item is created in that flow itself I could have written another action would say if my form word is new and then please add it as yes because I just want it on the flow so right now it doesn't know now if we head back to this flow and if i refresh this flow you will notice that the flow has not run it's been over 26 minutes these are my previous runs the flow has not run but if I head back to ticket to edit the ticket and let's say I change the category changed it to IT click on save notice this change to yes I'm gonna head over to ticket one edit this and let's say I pick security click on save no does this has changed to yes so now in both these conditions because I have changed the value of the category column if I head back to my flow and refresh my flow you will notice that the flow will run and as you can see three seconds ago both my flows have run so this time I'm going to go ahead and edit this item and let's say I changed my description to testing I don't change the category value and I click on save now the moment I do this notice the description change money look at run the flow it is still no that's because this value did not get updated now let's say in this case if I truly change this value and maybe I'm changing other things as well but if I change this now I changed it from IT to security now when I click on the Save button no does this changes to yes and my flow will run so you can conditionally run your flows only when a particular column value has changed thank you so much for watching I hope you liked this video please do subscribe to my youtube channel thank you
Info
Channel: Reza Dorrani
Views: 27,774
Rating: undefined out of 5
Keywords: power automate infinite trigger loop, power automate infinite loop, infinite loop power automate, power automate flow trigger conditions, trigger condition power automate, trigger conditions flow, trigger conditions microsoft flow, flow infinite loop, trigger flow when column modified, power automate trigger conditions, power automate trigger conditions examples, power automate trigger when field changes, power automate trigger condition syntax, power automate
Id: oKN4_5o2NUA
Channel Id: undefined
Length: 16min 36sec (996 seconds)
Published: Tue Jun 02 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.