Script in Flow Designer, LIKE A BOSS!
[Music] [Applause] [Music] [Applause] [Music] [Applause] [Music] [Applause] [Music] [Applause] [Music] [Applause] hey everyone it's justin thanks for watching in this video i want to show you how to script like a boss in flow designer if you've seen some of my previous videos i'm a fan of flow designer i think it has the potential to democratize workflows for the whole organization so you don't need to be a servicenow admin to come in and do that and in the spirit of that i was working on something and i needed to do some scripting and if you've used flow designer you know that you can come in and you can do things like go into scripting mode right so you can fill out some of these fields but you'll see there on the edges there i can pick uh fields from using this little picker right so i can go grab you know something about the trigger the requested item and i can kind of walk my way there or i can um do a drag and drop kind of thing from over on the right hand side so i can go look up that requested item record i can go to one of the values on there and i can drag that that thing that data pill over onto my canvas for flow designer okay so that's one way of doing things the second way is to actually just go in and script right so i can say hey for email address i want to actually just write a script to do what i want to do and that works fine and well and everything but it doesn't allow the kind of repeatability and reuse of things within servicenow which is i think the key feature in flow designer it's like hey let's not just do something unique let's do something and let's make sure we can repeat and reuse it in different kinds of workflows so um so scripting is nice but i would encourage you to think carefully about that so let's use this example i've got here i'm going to send an email so if in that email maybe i have my use case which i had earlier this week was to send the current date and time i was running a job or running a workflow and basically in the email notification i wanted to say when the job started and when it completed now you do in workflow um and it works though have the run start time up here on the upper right but i was doing some things before uh while after the workflow had already started so the actual stuff that i wanted to document the date and time could happen hours or even days depending on an approval after this workflow started so the run start date time wasn't accurate for me i needed the current date time right before i started doing some stuff within my workflow so i could have come in here and said hey let me just script my email message and in my email message i could have had a variable for a new glide date time and put that on my email address or email in the body of the email so i would have had to build the content of the email within this script i can't just get the date time and then go use that in my email right so um what i did instead is i created an action in flow designer so here i'm looking at a flow um for this particular one that i want to show you i created one to say hey get the date and time once i've got the date and time if you look over here i'll have that available as a data pill to use in my email so what does that look like well i just made a simple action you can see here on the action has no inputs it has a scripting step where it basically says set the output variable of current date time or occur underscore data underscore time to new glide date time okay that's my scripting and i basically said hey pass that back as a basic date time to whatever flow is calling that and so we have that output we signed the output here so that when someone runs this they will have access to the current date time when that action was run and then we can just drag and drop that data pill as you see here into our email and start using it okay so that's like the primary small use case if you're going to go write a script consider the fact that it might need to be reused or you may need it several times and if you can make an action out of that then everybody else can use that and they don't have to know scripting they just know that hey one of the things that's available to me when i come in here and say i want to add a new action is going to be get date time so it's now going to be an action that's published for everybody to use so you in the same spirit of flow designer and immigration hub have created something that people can reuse and use over and over without having to have the knowledge of scripting so gone right excuses of i can't do that in flow designer yes you can do it in flow designer but do it so that not only are you going to get value from it other people are going to get value from that as well so let's take this one step further before we wrap the video there are hundreds i think there's actually thousands of script includes within service now so things that you can do from a scripting perspective so i have this one example this is a script that's included i think it's with the goal framework but basically it says get the list of strategic objectives uh based on the business unit id right so we see there's some scripting going on here it's already pre-built it's read-only i can't really do anything with it but this isn't something i can use in flow designer i can't go past the business unit id currently um and then have it go look at the two different types of strategic objectives there's one based on the business unit so business unit strategy and there's another one based on enterprise strategy both of these extends to the strategic objectives table so they're extensions of it and have their own values but we can look up the business unit id for the business unit strategies and then by default if it's an enterprise strategy that's also a strategic objective for the business kids right so what i did in flow designer in the same way that i did a date time i did a get strategic objectives action and this one has a simple input and that's the business unit id right so we've got to pass that value because we know that script uses that business unit id on the scripting step we're just calling that same thing get strategic objectives and we're passing the business unit id to that function right so it's going to run this script over here but we're going to do it from flow designer using this little script over here and on the output it's going to assign the list of strategic objectives that come from that and we just do our output assignment here as well for that to come through so what does that look like over here first in our flow we're going to look up the business unit id so we can pass that sys id to that action which will pass it to that function that's in that script include so there's our look up for the business unit id and then we're going to get the strategic objectives this is calling the action that i just showed you we passed the sys id for that particular um business unit where we looked up it and then i'm going to get passed back a list of strings or a list of sys ids because of an array of them actually that script builds out a list of them and then for each one now i can go look up the actual records in the strategic list or strategic objectives table what that's going to give to me is a list of all of those things for me to use somewhere in my flow so i'm going to have a list of strategic objectives and i can go do i can put them in an email i can go update the records i can go do something else with it right so this is uh i've used the script and now i have the all that information that data ready for me to use inside of my flow so let's test this out i've got a test button up here i'm actually not going to save or activate this was just for demo purposes to show you how you can script within flow designer but make those scripts reusable so let's just select any random requested item and we'll run the test and that will execute everything you just saw in the canvas behind me for this particular flow and what i'm doing this for is because i want to click on the test results or the execution details and show you what happened number one i get date time it got the current date time and made that available for us to use in this particular flow the send an email now has that get that date time as part of the email so we see here i can look at the actual contents there was what was in my script and there is the date time that came back from that action that we created now what about that business unit so we looked up a record we said where the name is i t and yes it found the business unit where that name is i t and then it passed it to that get strategic objectives so that wouldn't bring that script to this long script that we were looking at here i didn't have to put any of this in my flow i just called that method from my flow and it got me a list of sys ids of all the strategic objectives and enterprise strategies for it or for the company and pass those back and then once i had that list of strings or list assist ids then i looped through and got the actual record so we can see here we have the lookup record where it looks up the strategic objective for that particular sys id and it did that 23 times it did it for each one of the strategic objectives that came back from that particular function so that's it for this video i wanted to really illustrate that you can still script and take advantage of the thousands or hundreds of scripts that are included in the system but have those populated within your flows and reuse them it's really important when we're talking about flow designer to have something that's repeatable reusable we go edit it one place and it affects everything and so our maintenance is costs are low and then like the point i was trying to make earlier is that you can make things these things available to citizen developers or citizen workflow designers so they can come into flow designer and not have to know how to script right so we're making it accessible for everybody to use uh in their workflows and take advantage of what the system has to offer and still allow for the scripting the capabilities that we come to know and love from servicenow i hope you found this video helpful if you did please like please subscribe or share with somebody who you think might be interested until next time i'll see you on the next one [Music] you
https://www.youtube.com/watch?v=8PThVarMn3o