logo

NJP

Create an Error Handling Subflow with #ServiceNow Flow Designer

Import · Nov 25, 2022 · video

hey everyone welcome back to another go with the flow the series where I teach you a little bit about servicenow flow designer with this few video edits as possible now one thing I love about flow designer is the error Handler function which you can see right here I really like the idea of sending an incident to the servicenow team like I do here where I've created a task action then I'm using the table incident and I'm populating the short description the assignment group and the description with stuff that will help me solve the flow problems now there's two things I've always disliked about this number one is that I always have to create these manually [Music] and number two is that there's no way to find out what the actual flow name is from the arrow Handler so I'm typically doing stuff like copying the float name and then pasting it manually into the short description of the incident that I'm creating now thanks to a servicenow developer named Jonathan Crosby whose LinkedIn will be in the description below be sure to check them out he's showing me the way that I can find out the name of the flow that has failed so that the incident can get created and named automatically and now we can have a universal subflow we don't have to build this task every single time we just build it once in the subflow and we add the subflow to every flow that we want error handling on so at the end of this video we will have a subflow and that subflow will create an incident that contains the name of the flow that failed it will contain the code and the message that the error Handler gives us and for bonus points it will give the servicenow admin team a link in the work notes to actually get to the failed flow context nice here we are on a subflow I'm calling it the error handling subflow and with subflows you have the opportunity to create inputs and outputs and input is something that will be prompted when you use this subflow on another flow just like you do with any other actions when you're doing lookup records it's asking you for the tables and conditions when you use this subflow it's going to ask you for anything that you've defined inputs for so we're going to Define two inputs one is going to be code and I happen to know that that is an integer and we're also going to have message which I already know is a string now I'm also going to define a flow variable really quick and the intention of this variable is to figure out what the context ID of this subflow that's running is so we know the subflow ran that means you should have an entry in the sys flow context table and we want to know what the ID of that record is so we're going to call this flow variable this context and it is going to be a string as well now you see in my flow variables that becomes available for me to use throughout my flow if you have flow outputs that means your subflow will have data pills that you can use in the main flow that calls it this flow does not need any outputs because it's just going to do something and be done so the first thing we want to do is set the value of that flow variable with a script so we're going to go into our flow logic and we are going to set flow variables we're going to pick the variable we wanted this context and we're going to use the script Builder here here and I'm going to paste in a script now what this script does is it goes and it gets the context ID the sys ID of the sys flow context of this triggered subflow the important thing to remember is that it's just an ID it's not the whole record so we're going to take this value and we're going to go do a lookup so that we know the full record of the sys flow context of this subflow so we've set the flow variables we're also going to add good annotation because we're good stewards of our flow now that we've got the context ID we're going to use it to do a lookup for the entire sys flow context record so we're going to add an action we're going to use the look up record action its table is going to be sys flow context and we want the record where the sys ID is equal to our flow variable this context let's be sure to annotate it because we're good stewards of our flow okay so the problem is that we have got the cut the full context record for a sub flow that has run but how do we get to the parent flow now if you look at the sys flow context table you will see that there is this column called Source record and Source record is a reference to another sys flow context of a flow that is called this subflow so every subflow is triggered by a flow and it's the source record that stores it for us so we're going to do another lookup in order to find the sys flow context record for our source so we're just going to add another action it's going to be another lookup record it's going to be on the same table sys flow context and this time we're looking for one where the sys ID is equal to the sys ID of the source reference of the number two lookup that we did right so in in Step number two we looked up the entire flow context for this subflow and so we know that the source record Society is the actual flow context for the main flow so we're going to go into the flow engine context record and we are going to get the source record and we're going to be done with that and let's annotate it because we're good stewards of our flow contest for flavor flow now that we have the sysflo context of the main flow that made this all happen now we want to go ahead and create an incident send that to the servicenow team so we're going to go to action create task this is going to be on the table of incident and let's start adding some values we know we want to assign this to the servicenow admin team and we want to make sure that they know exactly which flow failed so let's say short description flow failure for now how are we going to find the name for that that's easy we've already looked up the flow context so let's go to that and it has a column called name and that is the name of the flow that has been fired now let's also go to our description and put some handy stuff in there now you remember it's the main flow whose error Handler holds all the information remember at the very start of this we had flow inputs where we're asking for the code in the message that what the parent flow is going to send us so let's put code and message in our description and we'll take our flow input of code we'll drop that into description flow input of message we'll drop that into the description and we are almost done a lot of people would leave it right here but since we want to make things as easy for our servicenow admin team as possible we want to load our worknote in with a UR RL so they can just click and go to that workflow context I've done a couple videos on how to put pretty hyperlinks into emails and journal Fields you can check up in the corner there's going to be a preview up there highly advise you check those out and before we do that I just want to show you how I know this can work so we're going to go look at our flow engine contexts and if you actually look at one of these you'll notice that the flow context record has this UI action called open and operational view now if you click that it pulls open the flow designer interface and shows you the context of that failed run it wouldn't that be handy for the admin team to have so to figure out how they did it I just right clicked and edit the UI action and all they're doing in the UI action is using this window.open and they're going to this part of the URL they're opening up the flow designer page with operations context and the ID of the context and they're opening up in a new tab we can do that just as easily using the code tags inputting into the work notes so I'm back in my error handling subflow I've got the work notes up I'm scripting it and I'm going to use this script the first thing we need to do is find the sys ID of the main flows context and we did that with our number three lookup here but we can't really drag the data pills into our script so you can do that by building out like FD underscore data dot the third lookup record dot the record itself dot sysid okay that's how we figured out how to get the value in script so that takes some getting used to but now you know how to do it and all we're going to do is we're going to build a simple ahref we're going to go to that area that the UI action sends you to we're going to drop the lookup assist ID in because that's the context of the flow we want to look at and then we're going to say Target equals blank which takes to a new tab and then we are going to give it a friendly name go with the flow in a new tab and we're going to give it a friendly name go to the flow context so we've gone ahead and saved and published this error handling flow just a quick review we declared a flow variable called this context and that is to figure out what is assist ID of the context of this fired subflow we use a script for that then we did a lookup to find the full record of this subflow context then we did another lookup to look for the full record of the source record of the subflow and then we created an incident which populated the short description with the actual flow name we forgot from a script we populated a description with the code and messages that the main flow sended us via parameters and then we created a worknote that is going to provide a hyperlink to the flow context let's go back to our just some flow now here's the case where we're going to have to say goodbye to our formally completely manual error handling incidents so we're going to go to subflow error handling subflow now you'll see that it's asking us for the code and the message why is it doing that because we defined in the subflow to inputs called code and message let's input that with the similarly named data pills from the error handlers let's just feed code into code and let's feed message into message all right let's give it a shot hit test I'm going to pick a random incident now this flow is built to fail I'm not going to go into details about how I made it do that but this flow will indeed fail and therefore cause the error Handler to trigger let's view the execution details so you can see that it's caught some errors and it has successfully run the error handling subflow let's open that context so it's completed all the subflow actions successfully and it's created the task let's see that it's created inc001-0212 let's go ahead and click on that let's open the record itself it has assigned this to the service now admin team is short description is flow failure for just some flow so it's determined that name automatically that's awesome and it's put our code and the message of the error and if we check out the work notes we see this go to flow context and if I click that it opens up the flow context for that main flow that aired out so there you have it folks in under 15 minutes we created a universally applicable subflow that does automatic error handling and you can make it do whatever you want we used an incident and we use hyperlinks to get us to the actual flow context now your servicenow admin team can have everything they need to both automatically detect flow failures and go directly to the context of the failure hope you found something useful in there and I will see you on the next one if you're a servicenow expert looking for better opportunities but maybe your resume or LinkedIn profile isn't doing you justice reach out to me via LinkedIn or the email pictured here as I offer both career coaching and recruitment services and if you're a servicenow customer or partner you heard that right Robert fedorik now does servicenow recruiting with a 1500 subscriber YouTube channel and mailing list and thousands of LinkedIn followers let's make sure your open positions get first go it's a prodigious pool of servicenow resources reach out via the emailed picture here

View original source

https://www.youtube.com/watch?v=Br5p7inqbXw