logo

NJP

ServiceNow Flow Designer loop | ServiceNow loop in flow | ServiceNow Flow designer tips and tricks

Import · Aug 23, 2022 · video

[Music] hi all and welcome back so in today's tutorial we'll be looking into one more one one of the controversial Topic in the development committee okay so that's about what is better workflow or flow there are a lot of people out there who are big fan of workflows and there is another segment of developers who want to get upgraded to the flow designers okay and explore the new featur of flow designer whenever I discuss on this particular topic or on this particular controversial topic we can say okay there is one statement which I always heard from the people who are fans of uh workflow is like whenever they use workflow if they want to loop on certain things right it's pretty easy for them to loop on certain things okay but when it comes to flow this iteration is not possible or it is quite difficult okay so in today's tutorial we'll be breaking the math out and in today's tutorial we'll see how we can loop on certain things okay create a loop on Flow designer okay so let's get started as you can see on my screen this is my personal development instance and let's jump directly to the flow designer so we'll go to the flow designer first and on Flow designer we'll create a new flow okay so I will go to the flow I'll give it now create low Loop okay I will not change anything out because we are not working on in use case Okay as a part of this uh tutorial okay so create flow Loop so whenever you create a flow the first and the foremost thing is you have to define a trigger so as we we are not working on any business use case over there I will just keep the trigger pretty simple so I will make it a schedule job probably I can see it once okay run once I'll Define some time so it should be 29 something okay done and now we have our trigger with us okay now the next thing what we have to do okay in order to for example let's take let's start with a simple use case so consider a fact you want to log certain message in your system logs okay 10 times so how you can do that so what you have to do you have to just click on the three dots at the top of the flow okay and there you will be seeing a flow variable so we will be defining one flow variable okay so you can click over here and I can give it a name as Loop count I'll give it a name as Loop count and I will what we will do I will make it as a integer okay and now we can see we got the flow variable over here perfect now if I want to Loop it 10 times right the first thing what I have to do is like to set that particular Loop count to 10 so how we can do that so you have to go to the actions okay and we can type set set flow variable oh sorry set flow variable in the flow logic and here we'll be pulling that particular that variable out so we have one variable over here which is Loop count so we will pull that out I we will select the loop count and we will set it to a value of 10 for an instance okay and turn so what we did till now we have created a flow variable and we have set it out to a value of 10 okay now we are all set now if you click on ADD and if you go to flow logic so you can see there is a a logic flow logic called do the following until so it's like a do while so you can see this interface come so it shows do the folling whatever we Define over here until this particular condition made so you can say it's like a do while kind do while Lo okay so let's define so what we have to do we have to just showcase a m we have to just put a message in the logs so we'll go logs log and we will add a message to the log so it getting load I will keep it as info message and I will give techn Mom please oh please subscribe to techn okay and we will mark it as done I will just copy this message in order to see it in the logs and till what particular time we have to do this thing you can keep on adding the actions over there so you can Define until and in until and let's do one more thing so once the log is done we have to decrease the count also right so currently the count is 10 so stop decrementing the count so how you can do that again go to the flow logic you can go to set flow variables okay now over here you just click on plus select the variable okay and over here we'll just simply drag and drop it over here so now currently it's setting the value to 10 only why 10 because we are setting it to 10 over here now you can see there is some small icon over here right so if I click on here so this little icon okay it helps us out to work on this um to Define certain Logic on this particular attribute so let's do that so if I click on this so it's loading the magic and I think I have to scroll it over there so it's showing a lot of things math dat time string blah blah blah blah blah so we will go for Math and if we scroll down there's something called subtract so we want to subtract one right this is what you have to do so we are decrementing the count apply and I think we are done so if we go back [Music] so so if we go back we can mark it as done okay so here we have set the variables value now we can Define till what time we have to do this thing okay so you can click on the until and on until we have to do you can simply until this particular Lo count is let is remove this out is zero and done so we are done with this logic okay so we have set the work flow variable to 10 then we have added a log we have ADD do while then we added a log then we have decremented the value for flow variable and then we we have defined key at which particular state it should get terminated we'll save it out we will activate it out oh let's not activate Let's test it out directly so we'll send the test okay your test has been finished successfully so let's check it out so what I will do I will go to CIS logs do list and say log and we will search with the message Star techn so you can see we got this message 10 times that means itated this log util 10 times okay and you can see the execution is by flow designer now let's enhance it out okay so I came back to the flow okay now for an instance you want to create an incident right create an incident for example five incident I will not go with 10 so we want to create five incident so I will just set this variable to five whenever the flow gets executed and we can go go to I will delete this out or I can keep it as is it's not a problem I will click on this plus to add one more action and I will give action or here we can give create record which record we want to create I will select table incident I select short description as this right to technog and also I will set color to for example table duor or system administrator okay done same logic we are not doing anything I'll save it out and let's test it out so I will run the test again so it got finished everything is fine yeah everything is fine now let's see if it has created some incident or not so we'll go over here we'll go incident. list and you can see we got five incident with a short Des please subscribe to techn more if I do show matching it will show it has created F so this is how you can look on certain logic certain action you can make the variable also Dynamic okay if you want okay uh in the flow designer so it's kind of myth breaker video that you can do the looping in flow designer okay so this is all for today's tutorial hope you like this out please subscribe to my channel so that you will get this kind of videos notification in future also till then stay safe stay happy and have a nice day thank you

View original source

https://www.youtube.com/watch?v=JAriE-_YvXo