Replacing a Business Rule Using #ServiceNow Flow Designer. Update parent from child.
this episode is brought to you by sacon which is on my list of apps with the most potential for game-changing savings talk to your organization's mobility manager and they'll tell you the nightmare of managing multiple carriers per country each with their own offerings contracts and integrations sake sakon abstracts and manages this for you eliminating the swivel chair mobility management work and giving you asset and configuration data you can trust sakon is mobility managed check the description below hey everyone welcome back to my channel my name is robert fedorick it is so good to have you here i am experimenting with a new format tonight i am starting a new series called go with the flow where i am going to be building on flow designer and i'm doing it kind of live the point here is for me to save on edits and just get you content faster so bear with me because this is the first time i'm just talking into the camera and not relying on edits i will not rely on edits i will not rely on edits i will not rely on edits okay so here's the scenario and excuse me because i'm not going to be looking at the camera all the time because i'm going to look at my screen to remind myself of what i need to be talking about okay so the scenario is that we are living in a world where we have incidents and the incidents are managed by deploying various incident tasks so here we have a case where where able tutor is saying his access to application xyz is revoked and that's a big problem because he's our application xyz guru so as a service desk i am going to distribute a bunch of different work to different teams so i'm going to have somebody uh go into application xyz and see if there's been any access errors then somebody else is going to call the application xyz vendor to see if it's a licensing problem and then somebody else is going to check the actual hardware that able tutor is working on so a bit of an imaginary scenario there now what our process team wants us to do is say you're going to put the incident on hold while everybody else goes and does their incident tasks but what happens when those incidents task gets closed maybe they want us to kind of kick the incident back into an in-progress state so you just abstract this to say i have something going on on a child record and when it happens i want the parent record to be modified in some way now traditionally this is something that you would go to business rules for but i think that thinking of flow designer first is actually a pretty valuable exercise and i think that for a few reasons the first reason is that flow design allows you to do stuff without code business rules basically always have to do code 99 of the time so because i don't have to have code that means i can have admins that are strong and capable just not coders do stuff that would traditionally be restricted from like coding and business rules the second thing i like about flow designer is that it has really good error handling so if the whole flow fails then you can use this error handler and essentially build a whole new flow for stuff that goes wrong this is excellent because in the case of business rules half the time you can't even detect that something has gone wrong and by the time you know it's gone wrong then you have to do stuff like put in log statements and go back to the syslogs it can be pretty messy with air handler i can do a whole bunch of different stuff whatever i want another thing that i love about flow designer is that and you will see this later on in the shelf flow designer allows you to test the flows before you activate it and i find this is just a much better way to figure out if the thing works as intended much easier than say business rules which would have you essentially roll back through the entire process to get to the point at which the business rule would even trigger so let's uh just a quick rehash of the problem we have incidents and whatever state they're in if one of their child tasks incident tasks gets closed then we want the incident to be put into a state of in progress let's go to the flow designer so here we are in the flow designer and always with the flow designer first thing you need is a trigger so let's go add trigger and we are going to use the updated trigger not created or updated because for these incident tasks to be closed they would have had to already been created so we just interested in updated and what table are we working off of we are working off of incident task what is our trigger conditions i am going to say when the state now you might say is one of closed complete or skipped but i'm going to say changes to and changes to complete or changes to incomplete or changes to uh close skipped the other thing i'm going to do is make sure that the run trigger is for each unique change okay so i want this to happen like i could be in a world where incident tasks get closed and reopened and closed again and i want to be able to cover that base i want this flow to happen in any time that a single incident task is changed to close complete or any of the other closed values so our trigger looks about right i'm going to click done and now it's time to do a flow action it's going to be pretty simple one all we want to do is update the parent of that incident task so let's go to add action flow logic or subflow we are going to add an action and we are going to update a record there's our update record now this is what i love about flow designer because there's all kinds of things to make your life easier if i was coding this i'd have to do like glide record and figure out what the thing's parent is and do again here in flow designer i can just say listen i want to go to the incident task record which we know from the trigger and i want to go grab its incident and i'm just gonna drag that into the record uh finder there now it already knows that the table that you're looking at is the incident and now we wanna know what fields to update so i'm going to pick the state field and let's put a state of in progress and because we're going to be a little bit fancy let's assume that in most cases the incident task is going to close us some work notes we want to make those traverse up to the incident so that our incident manager doesn't have to go dumpster diving through the incident tasks to find out valuable information so let's add a field value and let's dump a whole bunch of stuff into the work notes so let's go to the work notes and let's start building out here so we are going to say last um no let's go incident and then let's grab the number of the task incident task and let's grab the trigger record incident task record number go and let's say has been closed by who would it have been closed by probably the person who last updated the record so let's go to the incident task record and let's go to the updated buy and let's put a couple character turns in here and let's say the last work note is the work notes from the instant task records let's grab work notes put that there and maybe also i want a closure code if it's got one i don't even know if instant task has a closure code to be truth closure code and let's go through the instant closed notes excellent so not only will we change the state of the incident to in progress but we will also leave a nice healthy breadcrumb trail of exactly what happened in the incident work notes so that the incident manager knows exactly what's going on all right so that looks about ready for update incident record that's done and again let's take advantage of this error handler so let's add an action or flow logic or subflow now in most of the examples i've seen on docs it they just use the log action which is fine but i'm going to pretend that this flow is super important to me and it's not enough that i have to go dumpster diving through log files i don't even know if it's dropped to the log file i want to be informed that something is gone wrong and what better way to be informed than with an incident so let's go to action let's create an incident and remember that this is only going to happen if the flow fails all right there's a huge weight there so sorry about the pause so we've got the create task action in our error handler and what type of task are we going to create we are going to create an incident and we are going to add a value so uh we want to make sure this goes to the servicenow admin team right away so let's go assignment group is service now and then let's also put in a nice short description so add a short description help if i can spell all right and let's say um let's copy this flow title and let's say flow has failed okay and let's say on incident and let's go grab the incident number for the incident where this flow has failed so uh we know we we know the incident from this update record uh action that we had earlier so let's grab the incident record and grab its number okay and it would probably help if we have a nice description in there too so let's add a description and let's put in some rich information here as well and say let's grab that incident number thing again so let's incident record number uh and let's put a short description in there too instant record short description okay now error handler also gives us some error statusing information that we can access so let's go code and go through our error status and grab the code object put it there and then put and then put message and grab the error status message all right let's hit done there so now we have a very simple flow but it's got the right trigger so when the uh incident task state changes to any of these and it's for any unique change so it's not just measuring this once and then never doing it again for that incident task then we update the record we change the state and then we dump a bunch of information into the work notes and then if the whole thing just goes kibash on us then it will create an incident and uh send it to the servicenow admin team now the last thing that i love about flow in in place of business rules is because i can test this super super easily and that's what we're gonna do so let's grab uh an incident task from this sample incident let's go to our flow designer and let's say test and let's grab that task number and let's run the test all right test is finished let's go view it okay and we see that the incident it simulated the incident task being updated and it's done the update record so we see that so we didn't have a closure code or a work note on that incident task but if we did it would have been put right there we also see that incident task this has been closed by rd fedor excellent work okay let's try it again but let's force a failure so what i've done is i've gone to incident task prior to my recording this episode and in my incident task list i have this incident task that has no incident parent so this should cause the flow to fail because it has no incident to drop information into so let's retest this except we're gonna do our parentless incident task and let's run the test let's look at the results okay there was an error caught because it was trying to update the record but of course there was no record to update and so it's gone to the error handler and completed that so let's see what incident that came up with okay so it's created an incident let's go take a peek at it incident closure failed on incident awesome let's open the record i don't have description on this form so let's just go to the show xml by the way if you don't know about show xml there's gonna be a video uh pop up here on my youtube channel right about here and that will give you a video on what ex what show xml is all about it's an awesome administrative tool you should totally check it out let's find the description and we see okay code message field record value null glide record is invalid awesome so now you've seen how you can use flow designer in place of business rules it's not a 100 solution you can't completely replace business rules of flow designer but it's always a good exercise to start with flow designer if you like this new format be sure to drop a like on the video be sure to hit that subscribe button if you disagree with anything i've said in this video please leave a comment and we 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 fedoric now does servicenow recruiting with a 1 500 subscriber youtube channel and mailing list and thousands of linkedin followers let's make sure your open positions get first go with the prodigious pool of servicenow resources reach out via the emailed picture here
https://www.youtube.com/watch?v=LrvD9TG1aWE