ServiceNow Advanced Reference Qualifier | How to filter the Assignment group based on Assigned To
hello and welcome back to the channel so have you ever been in the situation where you're on a task record let's let's call it an incident and you want to assign your incident to someone else and you know that person so you put Bob's name in the assigned to but you're not best friends with Bob so you don't know what assignment group to be in there and when you go and click on it it just returns all assignment groups or at least all perhaps filtered on ITIL me so what do you do well in this video I'm going to show you how you can create an advanced reference qualifier the kind of back filter the assignment group based on the person you put in the assigned to so if you want to see how easy that is to achieve stick around and let's go do it [Music] that's right I'm back with another video so we're gonna see how we can almost backfill refine the assignment group based on the assigned to um so let's dive in and and have a look I'm going to put some glasses on so let's have a look so we've got an incident form so we're going to use an incident example we're going to pick on Beth Anglin as our assigned to person as well but let's see what it does at the minute so out of the box if we're on an incident click assignment group we get 42 groups right if we stick in a demo person Beth and then we click on assignment group we again get 42 groups so there's no filter I think the simple filter simple filter on assignment group at the box is um if the group type is ITIL or contains no types right it just just builds everything it's quite naughty filter group so let's let's see um let's see how we can achieve a better filter so the way we're going to achieve this is by an advanced reference qualifier in order to do that we're going to need to create a script include I've already done a video on Advanced reference qualifiers go and check that out but let's move on to the script include which I have already created because there's a beer type and it's not too heavy um but you don't want to see me sit here typing um for 20 minutes so let's just dive into that I will put the code um snippet Link in the description so don't worry so I call it assignment group filter if you've already got like an assignment group utilities if script include or a reference qualified script include you can consider putting it in there but I've created a separate one for ease of demonstration so I call it assignment group filter one thing I am going to say and I always say this all the time put a description and make sure you do it um you'll love yourself if you find it later on in life so let's have a look so we've created a function called refine assignment group and we did another load of scripty stuff in that function right and it does look quite daunting but we're going to talk through it we need to call this script include from our reference field so let's go back to the incident itself and let's go back to assignment group so assignment group is the field that we want to put the reference qualifier on because if we pick if we put Beth for example we want assignment group now to be filtered based on Beth's membership so if Beth is a member of the groups those are the only groups that we want to see in the assignment group field understand so we want to filter that if we go into the field itself so there's many ways to do this but I always do this right click we go to dictionary and we look at how it's being filtered a minute so we've got a reference qualifier condition remember this is on the task table okay task table so anything that we change here is going to be inherited from extended on extended tables so what extends task exam question incident problem change pretty much everything right so if we do it here we need to be mindful that we could make a big boo-boo so just be careful um I'll edit something in there I think that there's there's definitely a snippet to be put in there oh that's a boo-boo so what we're going to do is go to a dictionary override so there's only one for incident but if you don't have one you can create a new dictionary override for incident this video is not about what dictionary overrides are but essentially it allows you to override the dictionary for task so you can put in different reference qualifiers then this one I'm gonna I've already got this on a code uh code a notepad so I'm just going to pop that in there and then we'll explain what it's doing okay so in this reference qualifier I'm telling it I'm about to put some JavaScript in here now what I'm doing is I'm I'm initiating that script include that's that new Global silent group filter where do I get that from up here that API name you could just call it using that but I tend to use Global dot because it it kind of um it helps out when you're you're crossing different scopes no not the video go with either this is initiating the script include remember this bit refine assignment group well what's that what is that well hang on we can see that here right so that here this is our function this section here we go all the way this is our function that we've created script include and within that we've got one Function One function so what's this then current dot assigned underscore two what does that mean so that means we're passing the assigned to in a demo case Beth Anglin as a parameter into that function okay script include function path parameter in simple stuff all right now let's go to the script include how are we doing for time let's have a look oh we're all right oh I should say actually before we before we continue if you haven't yet subscribed make sure you uh subscribe to the YouTube channel and also check out the service docs podcast um that James downs and I do we try to release it every other Wednesday uh we've been doing some lives as well for checkout and they're quite ad hoc actually we don't tend to plan them but just uh keep your eye on if you smash the Bell icon on YouTube then you'll get notified whenever we do a live right anyway let's carry on so this function what does it mean it allows us to refine the assignment view it's not going to pre-populate the assignment group it's just going to filter that list do you remember we had 42 it's going to kind of filter it down a bit so let's have a look what's the first thing we do we are declaring a groups array right so we're saying we're going to we've got an empty array and we're going to put stuff in it now what we're saying here is that assigned to that we pass in remember from the advanced reference qualifier let's just flip back so you can see it there we go right now we're saying if that is empty do this so if there is no assignment group we were going to go to the user group table which is this list groups you can see what we're doing here right okay so it's this so that's going yes I'm going to do a query on the groups table I want to find active groups and I'm going to run this code encoded query which is type like and I can tell you that's the the sysid for ITIL the type it till now you could filter put in a different type in there if you want to um you might need to based on what's on your system but this is basically saying return all the groups where the type contains ITIL that's it right while you have one of those or if you have one of those then we're going to go into our while loop so that is kind of if we've got something so if we've got anything in that query now go and loop through them and when we find one so let's say we've got 10 for each one of those 10 push the sys ID get unique value into the array that we declared in line eight so get unique value that's um a out of the box method that we can use and it's just getting the sysid of the user group so put those sys IDs of those user groups into the group array simple stuff right you can actually go to the um to the record and then start um do putting the encoded query in and see what it uh what it do to follow along else right so we've already said if we haven't got an assignment group do this else which means obviously if we haven't got something what's the opposite well we have got something so if we have got Beth no if we have got an assigned to in there then run this logic so this is going to a different table this is a group member table so this table is let's just pick on this group table that we're querying there I hope I'm not over explaining this do put a comment in if you think I do um I do tend to ramble a little bit how are we doing for time I don't know eight minutes okay right this is uh poor example but this line here this table here is looking at a kind of group membership group membership here so you can actually go into them so if you've got uh right click um and then go to definition or you can go to there you go show definition show data you can go in those anyway right move on to the group membership table which is the link between the group and the user this is saying find me where the user is Beth because Beth is the assigned tuner use the case and the group so the associated group type is Idle so it's very similar to that so this is return all the records where the user is the assigned to Beth and the group that they're assigned to is an ITIL group still makes sense I'm hoping again same logic if it finds something then go wild through the loop now this time we're still going to push to the array so it's very very similar we're still going to push it into the room what that means we're gonna we're gonna push stuff into that array right we're gonna um add to that array but this time we're going to say the group member dot group sysid right so the group member is that link between user and group we want to get the group out of the group field and we do dots um sorry we dot two string to put the sys ID in there so it's a little bit different from get unique value but this bit is important if you don't do this bit it'll just return um the same kind of group over and over again so just make sure you do that with most of my stuff I always urge get it in there muck about have a play right in a subprod environment you can do that you can see what other things do anyway so we've pushed the array then here this last little bit is saying return sis ID in group three right so we've by line 38 we've got our array of sys IDs which is a list of groups right it's a comma separated list of group sys IDs that's what it is so what we're doing here this is simply saying is the sysid in that list of sys IDs that we're going to push it which is this so let's go and take a look at how that all works together so if we go back to our instrument in fact I'm going to use a history thing right that's great history incident boom straight back there did we put in the assignment group filter let's have a look Okay so we've still got 42 so perhaps we didn't say that so go back to our reference qualifier here and we're just going to save that save now let's try it without putting Beth in we should have a a smaller list there we go we've got eight we've gone from 42 groups to eight so we're now filtering and the reason that happens is the standard out of the box filter for assignment group on task is looking at um as I've said before idle or not the query that I put in the the top bit of the function is just looking at itel it's not doing any of the null stuff I just thought I'd cut that down right so just be careful of that anyway this is returning all the ITIL groups so now when we come to put in Beth's name here this time what we should see is that when we click on the assignment group that little list that was 42 and then was a is going to be even less now because what's returned this time is only the groups that Beth is a member of that have the type that contains ITIL and in this case it's Incident Management or service desk so now if I'm an agent looking to Route it to Beth perhaps Beth said the sign to me I can then select the right group to assign it to that okay so I hope you found this simple video useful and put it to good practice if you haven't yet subscribed please remember to do so smash the Bell icon you'll get notified whenever I upload new videos just like this one or James and I are going live on apps podcast until then I've been Russ and this service nerd
https://www.youtube.com/watch?v=p_1oOjahLy0