Approvals and subflows on #ServiceNow Flow Designer
hey everyone welcome to another go with the flow in this episode we are going to talk a little bit about subflows and approvals sometimes you have an approval process that is just complex in its own right and to put it in with the rest of a medium to complex catalog item means you're going to have just tons and tons of nodes in your flow and it would be really nice it was nice and clean and compartmentalized so I borrowed this example from the community where they said I have a request item and I have an approval group for the request item and if the person who's submitting it is the only person in that approval group we want to skip the approval go right to doing the tasks otherwise if there's more than just the submitter in the group or if there is people in the group that are not the submitter at all we want to generate an approval and if the approval succeeds only then will we move on to the tasks otherwise we do nothing so maybe this isn't an approval that you would use at your organization but it's complex enough we could use it as an example to build a subflow out of we're also trying something new on this episode I've already gone ahead and created the flows and we're just going to talk about the flows that I built forget everything I think to each field because oh my gosh it's so totally boring let's start with the subflow and I'm going to walk you through this bit by bit so subflows always start with inputs and outputs let's check out what we've got here so I am expecting two inputs from whatever calls this subflow the first input is submitter and it is going to be a reference to the user table and it is mandatory I want to capture who submitted this requested item and have that as a submitter pass to this approval subplot then I am also going to pass the source Rhythm this is really handy to have especially if you're going to be putting approvals against the Rhythm it pays to have the Rhythm there also you might want to use variables for different logical Pathways so it just pays when you're using a subflow to feed it whatever task the original flow is on now we also expect outputs I have two outputs one of which is pretty obvious like what is the approval was this thing approved or not and it's going to be a string but we've also got an output called approval posture because there are cases within this flow where I don't want an approval to generate at all and I will be evaluating that before I even evaluate the approval so we have inputs and outputs they're very easy to build you just hit this plus sign and you fill out the name and what type it is and whether or not it's mandatory so if you remember as stated the flow was if this submitted by is the only member of the approval group then we just want to go right past you can't really do that in one statement you can't find out if there's only one person in that group and is it let's say Bob so the first thing I want to do is look up group member records where group is the random approval group random approval group is just a group I made up for this use case you might also pass in an approval group as a subflow input very simple setup here it's using the lookup Records action it's in the table of assist user gr member which is the membership table we have the group is random approval group I just selected that right from the list now the second thing I want to do is a second lookup on the group membership table and this is going to be a lot more specific lookup it's going to look up if there is a gr membership for the submitted by in the group of random approval group let's take a look at that again it's using the action of lookup records and its conditions are the user is the submitter what submitter that's coming from our subflow inputs so whatever workflow is feeding this subflow is going to pass in a user reference and that's going to get stored in our submitter input which we created at the top of the show and the group has to be random approval group so I'm specifically looking for the submit a buy to be a member of the group remember it's not enough that they be a member of the group is that they're a member of the group and only they are a member of the group so now it's time to use those two lookups in an if statement so I've got a simple if statement here I've put in a conditional label of approval group only has submitter as an approval and the way I'm doing this is figuring out is the count of my first look up one basically does that group only have one member and the second condition is is that only one member equal to their submitted bias so if both of the lookups only have one record returned we know that both statements are are true and if that's the case we want the approval to skip so what I'm going to do is populate that subflow output to approval posture of skipped so here's our assign subflow outputs you can find that under flow logic not actions so we're taking the approval posture flow output and we are setting that to skipped and that should end our flow if it goes down that path otherwise what happens if either of these two numbers are greater than one well if either of those two numbers are greater than one we know there's either more members in the group or are submitted by isn't in the group at all in which case we want to ask for an approval so of course our first action after the else is ask for approval this is pretty conventional we're going to use the ask for approval action and what record are we going to approve we need to approve the Rhythm that's going to fire this whole thing in the first place so we'd better grab our subflow input of the source request item then we're going to set the rules of approve When anybody in the random approval group approves so I just use this add group button and I selected the group manually again you might be feeding in an approval group into this subflow and you and you would just use your subflow inputs to put that in okay so now our subflow is going to wait and see if that approval happens and if it does what I want to do is take the results of the approval and set that to our output which is called approval so uh if I go to my assign subflow outputs again this is flow logic not flow action we're going to take the approval subflow output and we are going to populate it with whatever the results of number six was so I'm just going to do this manually so you can see what I did so you see in node 6 we asked for approval I'm just going to take the approval State and I'm going to drop it into that output so the output is going to be whatever the approval is after we've asked for Approved or our output is going to be this approval posture of skipped okay you might be thinking Robert that's a crazy approval workflow we would never do that it's okay I'm just demonstrating to you an exotic approval that we can showcase so that you know you can use a subflow would you really want to pack in all seven of these nodes into the request item before you even started talking about all the tasks and stuff that you're going to have in there so we've designed our subflow let's go to the flow and call it so here I have a flow called thing flow and it's meant to happen whenever I trigger the thing generator catalog item we've already got our trigger set up so the first thing I've done is I've actually called that exotic uh approval if you want to know how to call a subflow you just click this add action flow logic or subflow and just pick subflow and then you'd pick your flow from the list so I've called the subflow let's see what that looks like so I've selected exotic approval number one that's the name of our subflow and it has asked us for two things number one who's a submitter and number two what's the source Rhythm how did it know to ask us that now if you remember back in the subflow we designed those two inputs so whatever inputs you put on a subflow whenever you embed that subflow to flow those inputs are going to be asked for in that flow so when it asks us who this emitter is we just took the submitted by of the triggering requested item and when it asked us for the source Rhythm we just dragged over the requested item record okay so we know that the subflow is going to do everything we need for the approval so our main flow is waiting for the results of that so we can decide whether it needs to do a thing or not so we've got an if statement here it says if approved or skipped okay so what we have here is two conditions and those two conditions are based off the outputs of our subflow remember in the subflow we set the approval posture and we also set the approval depending on if we need an approval or not and whether it was approved or not so we know that it has been approved if the approval output is approved so we would drag approval over here into our conditions and Mark that as is approved or if the approval posture is skipped so we move approval posture output from our subflow node over to the condition and we mark it as is skipped and from then on is plain old ordinary service catalog stuff which tasks do you want to do in order I also put in an else statement because it could be that it was neither skipped nor approved but rather rejected and in that case is going to make an else statement and it's going to update the requested item with some comments that say sorry this wasn't approved always a good idea to put that kind of stuff into your comments or your work notes now let's use my favorite part of flow designer the testing mechanism I'm going to test this as myself I am not a member of that random approval group so this should ask for an approval and if approved it should then start by generating one of these tasks in sequence so let's test grab that last request item here we are on the test results and we can see that that exotic approval subflow is waiting how awesome is that but oh no how do we figure out what our exotic subflow is doing why don't we click the open subflow context alright now we see that it is done both the lookups and it is run the if statement that if statement has resolved in false because I am not the only member of that random approval group so it's gone down the else path no problem now let's ask for the approval and it's generated an approval record let me go back to the request item and see oh there's an approver so uh blah blah blah has been asked to approve and it's not run the assigned subflow outputs yet so it has no need to because it's still waiting for that approval to happen so why don't we go over to our request item let's mark this as approved we go back to our subflow and we're going to refresh now we see that it has completed that ask for approval what is it done after that it's assigned the subflow outputs it has taken the approval output and set the words as approved now we can go back to our parent flow output here we are in there let's refresh that it evaluated that if statement is true and now it is initiated the first catalog task let's go back to our request item and we see that it's generated the first of those two catalog tasks now you should always test all the pathways of your flows and so what we should do is figure out what happens if the submitted by is actually the only member of that group so I had this user his name is Robert Loblaw his friends call him Bob and Bob Loblaw has gone ahead and created a request item in the thing launcher blah blah blah is also the only member of the random approval group so what we should expect is that this flow has skipped all the way to the create tasks and not generating approval and if we inspect this record we see that no approvements have been generated and the first task of the flow has happened and there you have it folks basically subflows allow you to Define inputs and outputs so a main flow can send inputs to the subflow subflow can send its output back and you can use those just like any other variable or data element in your flows hope you learned something useful in that 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 fedoric 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 at the prodigious pool of servicenow resources reach out via the email picture here
https://www.youtube.com/watch?v=nqKAQg9hZUI