ServiceNow – Create Loops in Flow Designer
hi everyone in this video we are going to learn how to create loops in flow designer what do i mean by loops well does this code here look at all familiar to you it's a simple javascript while loop where we want to execute a block of code for a certain number of times until some condition is met and then we stop executing that block of code well you can do the same thing in flow designer let's find out how so i'm going to use a very simple example just to create five incident records it's not a very useful use case but we're going to focus on the logic rather than what we're actually going to be doing with the logic so i'll go ahead and create a new flow and call it create five incidents so our trigger is also not important for this example so i will just have this run every day at eight o'clock and before i go and start building out my flow the first thing i'm going to do is create a variable so i will save my flow first of all save often and then come to the three dots the ellipsis up here and go to flow variables and create one i'm going to call mine records okay and it's going to be a string close that so we can see now we've got a new flow variable called records here the first thing i'm going to do with my flow now is to set a value for that variable now it's not an action here you have to come to flow logic and then come down here to set flow variables we come here select our variable records and then just give it some value in my case it's going to be five so click on done and now i can build out my flow now i can do my do something until do the following until select that okay so now you can see we've got a little block of code here so we're going to be doing something in here until some condition is met okay in this block of code or in this block in flow designer i'm going to simply create a record i'm going to go ahead and just create an incident i will put in the caller as the system administrator and i will also add a value for the short description and pop in fix something until it's fixed okay so we're actually going to create five of these so how do we do that we've created a record what do we need to do next well in javascript you would increment the value of the variable so that's exactly what we're going to do here as well so i come to here and then go to flow logic again and this time come down to set flow variables again we select our variable records and now i'm going to go ahead and just drag and drop the flow variables here records over in here so the value will be set to five okay initially we did that right at the beginning of our flow so what we're going to do here is decrease the value of that by one so the way to do that in flow designer and this is one of the great things about flow designer now is that with your data pills that you use in your flow you have access to what we call these transform functions right here okay you can see the little fx symbol there so just click on that and we've got a whole library of transformations that we can perform on this value so the one that we want is under math and then we just scroll down to subtract what we want to subtract 1. okay click on apply and we are done with that action so after this little block has run through the first time we're going to decrease the value of our variable subtract one and now it will be equal to four and we're going to continue doing that until the value of the variable is zero so my condition here will be when the value for this variable records is zero and that's it okay so we can save this and we can go ahead and test it and once we do that we could go back to my list of instances here i've already got a filter here filtering according to the subject that i specified for the incidents and the flu just refresh this and we can see we've got five incidents now all the same caller all with the same subject again a very simple example it's not a real use case but you can see what the possibilities are as far as doing something until something else happens and here we've got basically a replication of what you would typically have in javascript with your for and while loops so that's it that's how you go ahead and do it in flow designer so i hope this little demonstration helps you with your flows in the future
https://www.youtube.com/watch?v=hRqJU2cZ74c