logo

NJP

Auto-Close Overdue Tasks Using #ServiceNow Flow Designer

Import · Mar 19, 2022 · video

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 fedoric it is so good to have you here welcome back to another going with the flow this is a series where i do minimal edits minimal edits minimal edits minimal edits minimal edits and build out stuff in flow designer just for the heck of it today we are going to talk about a use case that i saw on the community this morning and this one says how does one expire a to-do that has a due date but now the due date has passed and there still may be to do's not completed so the idea here if you read this thread is that once a due date reaches its expiry it's useless i've seen a few cases of this i remember a friend of mine was building a home management application and we were talking about how chores can't really go forward if you've got a weekly chore you just have to do it or you don't do it if it's past its due date it might as well not have been done so there are a few cases in our work paradigms where this might be kind of handy so what we're going to do today is use flow designer to automatically close records at their due date so to tell you the truth i didn't really know what the poster meant by to do's i did a search on docs and i found four or five different things that to do's apply to didn't know which one so we're gonna abstract this a little bit i am going to use the private task table this is uh came to servicenow with the advent of uh vtbs visual task boards and we've just got a bunch of private tasks in here and you'll see that a couple of them are due 12 days from now and a few of them are due 18 days ago now if you've never seen this uh days from now days ago you could just go to your settings here and it's under general under date time you could do calendar time ago or both and that way i get a date and a little analysis of uh where that date is relative to now but the key here is these ones clearly have to go because we're past their due date so let's go to flow designer and we're going to create a new flow here let's call this close private tasks beyond due date we're going to run this as system user and we'll submit all right so step one is always add a trigger and there's two ways we can approach this we could either say hey build a flow for the task and just wait till the due date and then close it but i don't know if any other flows are going to be running on this task i think it's just easier if i make this scheduled so every day will clear out the previous day's unexpired private tasks so let's add a trigger let's call this daily and we want to give people the full day to get to those private tasks otherwise we're going to shut them off so let's just run this at like 11 p.m so 11 p.m is what uh 2300 hours and there's our trigger it's going to do this every day at 11 pm so let's move on to actions so the first thing we have to figure out is which private tasks do we have to expire or change your state let's go to actions and let's do a lookup records look up records there we are always make sure you're getting the right one because there's a lookup record and a lookup records and that's burned me more than once so we're going to look up records against what table private task that's a great table to experiment on by the way because it's not involved in a whole bunch of workflows okay and the conditions so the first thing we know is i don't want to be querying over all kinds of private tasks that are already closed so let's make sure that active is true and we also only want to expire the ones that should be expired so there's beyond their due date so let's say due date is before today we could probably get really strung up in nuance here but for me if it works in general it's gonna be fine okay i don't need to order it and i don't need a max results so let's hit done so we have the first action is now we've looked up a bunch of the records so what do we do from there let's add an action and we're going to use some flow logic here and we're going to say 4 each so we've done the lookup and for each item in the lookup we want to perform an action so it wants to know what item or what is going to be the list of records to do the for each on and luckily we've determined that in our lookup action so i'm going to say get me the private task records that i found in my lookup record action so private task records drag that here and we're good to go let's hit done you see that we've got this new pathway so this is what do i want to do within the four each so let's grab this and we're going to take an action in here and we are going to update record which record are we going to update and this is why i love flow designer right i don't want to do any scripting to figure it out i could just go to the private record that will be an analyzed in each for each in each of the four each loops so let's drag that private task record over to our record selector then it knows that we're in the private tasks table and let's get started so what did we want to do we wanted to close those private tasks now if you ask me i would definitely want to know the difference between a task that's closed gracefully i.e the person responsible for it closed it intentionally versus something that was automatically closed for reasons okay so we're going to say the state is going to be closed incomplete we're just going to assume that the work wasn't done because nobody came in and closed it manually the other thing i'm going to want to do is leave a work note to give anybody who looks at these in arrears as information for them to tell them why it was closed so let's go ahead and come in here and add a work note and let's say this task was closed automatically because it exceeded its due date and i'm also going to say closed by and i'm going to copy the title of the flow if anybody knows a way to get the title of the flow in flow designer besides copy pasting it i would love to know please add a comment below all right so we've changed the state and the work notes that should be good now i'll say this over and over again in this series part of the reason why i love looking at flow designer before i start doing business rules is due to this error handler and if something goes wrong in this i want an error to jump out at me but i want to jump out at me in in um in a disruptive way i don't want to have to think about parsing the logs to see if there is an error i want to be told hey robert there was an error so best way to do that is with an incident so let's add an action and in this we're going to create a record or create task i should say and we're going to use the table incident and we are going to assign that to the servicenow group so assignment group is servicenow servicenow admins and we should have a short description flow failure and again we'll copy that and close the title drop that in there we want to make these things as informative as possible and in the description copy that and then we're also going to put the code and the message because that's something that the error handler will provide for us in flow designer so go to error handler bring over the code drop that into my description and also bring over the message and drop that into description so super simple didn't have to do a lick of javascript and i've got proper error handling so another reason why i love flow designer is because i can just test this i don't have to wait a day i don't have to write a scheduled job i can test this and make sure that it works the way i want to so let's go to test and let's just make sure we understand what success looks like so we understand that we have these private tasks some of them are due in the future some of them were due a long time ago so we expect that these five private tasks will have their state changed to closed and complete run a test viewing the execution details i love this interface in flow designer because it tells me if everything has been successful or not and i can dive into the details so let's see the first record that it updated was ptask one zero zero three let's validate that that was one of the ones that should have updated yep 18 days ago and it drops some information into the notes so the state has been changed to four its work notes is this task was closed automatically because it exceeded its due date awesome it's exactly what we wanted and we could also go through this and we could see the different uh records in that for each so we can validate every single transaction and our create incident error handler did not run because there was no error to be had so there you have it folks in a little less than 10 minutes we created something without a liquid javascript that can replace a scheduled job or a business rule for use cases where you're doing a mass update to tickets on a scheduled basis thank you to the poster on community for this question if you're new to servicenow you definitely want to jump on that community super super valuable for long form thought out content also one last thing i want you to know that i do recruiting and the reason you may want to use me as a servicenow recruiter whether you're looking for work or if you're looking for servicenow resources is that i understand the industry what other recruiter would be able to teach you how to do flow designer from scratch i've been in every position in the servicenow ecosystem i've been the ba i've been the developer i've been the architect i've been a project manager all right i understand what kind of skills these roles entail i've also been in the trenches and been looking for a step up into the right position so i understand both sides of this equation pick robert fedoric the next time you need a servicenow resource thanks for watching

View original source

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