Optimal Flow Designer Looping in ServiceNow
[Music] hey everyone it's Justin thank you for watching and welcome to my house that's Justin's house in this video we're going to talk about Optimal Performance of your flows in flow designer when it comes to looping so for Loops do until Loops there is some performance tweaks you can make to have your flows one run way way faster than they would if you haven't kind of architected them or designed them in a way that optimizes performance now I've shown this before there are some design considerations for flow designer and one of them I'll call your attention to is this limit for each and do until Loops to 1000 iterations okay so that right there is an acknowledgment that there's some memory tax or some overhead had when you go over a certain amount of Records when you're looping through them I saw this when I was actually designing my store application crawler that it was about 2100 apps in the store and it started off really fast and then it gets slower and slower and slower taking up to almost two days to actually complete that particular flow so let's look at the best practice in action to simulate this and not show my actual application just yet because it's not done I've made an at custom action that has an SSH step that reaches out to a mid server and just Echoes the application name of the store application right so I've got a table of all the store applications and here we're just saying go to the mid server Echo that at a command prompt and then move on okay so that's going to take a couple of seconds to do and then over time you know that takes a long time if you look at a thousand records so originally to show the difference in performance here I'm going to pull up a 4 or a flow right that gets triggered by a catalog item it's still loading here uh we'll let that load up here in a second I've got a lot of tabs open in flow designer but essentially what this does is it looks up the store application records I got a table of all the store applications that I got from a site map there's 2100 of those but in this lookup I'm going to restrict the results to a thousand right that's the best practice is not to do more than a thousand iterations in your FL in your for Loop or in your do until Loop then for each one of those I'm going to log something to the log file in service now and then I'm going to call that custom action to a midserver and uh and run that so that's going to take a good chunk of time I'll open this up and you can see where I did limit the results there to a thousand okay so that's the for Loop or that's the flow doing a thousand iterations in a for Loop okay my next flow is the same thing except I'm going to call a subflow to do the work instead of doing that in the flow with the trigger so you see I still have a trigger to call the service catalog but now I have a variable where I'm saying set this to zero and then I want you to call that subflue and run this in 50 record increments in the subflow and what it's doing is it's just totaling up that count until we reach reach a thousand so it's going to do 50 50 more 50 more 50 more 50 more until we get to 20 iterations with in this flow to complete a thousand records total so it's just calling a sub flow what's that subflow look like that's right here I've got the input which is going to be actually I don't have any inputs I'm just going to do a loop count and I'm going to pass that back so that we can do that counting back there in this in the flow so this one is going to look up the store application records but we're going to limit it to 50. just 50 applications and we're going to Loop through those the same way I'm going to log it I'm going to call that Echo to my mid server and then I'm going to send back to the flow hey I just did 50 right so it's going to run through that here's the magic when I do that in the flow where I do a thousand iterations and make those calls do that mid-server thing this thing starts um and I did this yesterday it started at 12 16 PM okay that's how long it took uh or that's when it started if you look here it's showing the last 50 executions of those a thousand executions so if I go to 50 here so let's just replace this with a 5 and a zero and now I'm on iteration number 1000 you can see it there and look at what time that completed at 1652 so that is four hours in change that it took this flow to run through a thousand iterations of a for Loop that's a long time but watch this if I look at the one where it called a subflow and ran 20 times through 50 records this one started at 1746 or 5 46 PM we do the same thing this only ran 20 times to do 50 at a time so we'll go to the 20th iteration and it completed you can see here at 1829 it took 46 47 minutes to complete the same 1000 actions using a flow with a subflow versus using a flow can you believe that it's just mind-blowing to me the amount of efficiency by breaking up my work into chunks of 50 that I was able to decrease the time almost three-fold almost from four hours and change to less or about 45 minutes and that is actually what made my crawler so much more efficient so the message to you here is if you're gonna do looping inside of your flows and flow designer move that looping activity to subflows and then limit the amount so you can iterate through them real fast and you'll have a very highly performant workflow where you can move through lots of data really quickly and not tie it up in the traditional flow I hope you found this video helpful if you did please please like Please Subscribe or share it with somebody who you think is interested in optimizing the performance of their workflows and flow designer and until next time don't forget to always be learning [Music]
https://www.youtube.com/watch?v=Bd_Cq2qyNDk