Reference Qualifiers in ServiceNow | ServiceNow Tutorial
[Music] so today we're going to go over reference qualifiers reference qualifier is a tool that helps you filter out data that's returned by reference field or list collector pretty much anything that goes and grabs info from another table and brings it back to your reference field there's three different types there's simple dynamic and advanced so we're gonna go ahead and start off with the easiest one which would be the simple reference qualifier so as you can see with this catalog item it is a it's going to use the simple reference qualifier so in this field it'll bring back any user who's active and email contains test so we'll go ahead and do that so you can see from the results here everybody has tests in their email and they're all active in this reference field it will bring back all users who do not have tests in their email so as you can see there's no test in the email so let's take a look at how to set one of these up so this is the variable for the users who are active and email contains tests so after you set up your type as a reference and you come down to the type specification you would set your reference to your reference table so this is the table you want to grab data from and bring it back uh in your reference qualifier here you select simple and with a simple reference qualifier uh it just uses a condition builder to bring back the data and it will only bring back whatever is met by this condition so active is true and email contains test so pretty easy so next we're going to go over advanced reference qualifiers they'll make the use of dynamic reference qualifiers a little easier to understand whenever you need to filter out the data and it's more complex and requires a scripted solution you would use an advanced reference qualifier now there's a few steps we'll go over with this one as it has more pieces than just the condition on the variable so here is the catalog item that we're going to use as an example so what you can do is select the user that you wish to edit and so you select the user you wish to edit and it will bring up in the remove from group field it'll bring a list of groups that the user is currently in and then the add the group field here it will bring back all the groups they're not a part of so if we change the user we'll see that change around so yeah as you can see all of those groups shifted so let's go ahead after seeing that let's take a look at how that's achieved so we're going to look at the remove from group variable first so as you can see it is a list collector type which is a is also referencing another table so again you'll have to select in your type specifications you'll have to select the list table that you wish to grab data from and where this varies is you're not going to use that condition builder you're actually going to call a script include and a function here so as you can see we're calling it the check user group script include and using the membership check function and then giving that function the variable of that user that we selected so let's take a look at that script include so as you can see right here when it calls that and give so it's using that function here it's feeding it that user that we selected we're going to that the table here the cis user gr member table and we're going to query it for that user that we selected and then while it finds any records it's going to push those groups into an array and then after you have everything that you want from your glide record query you will return that information so we're turning it right here so this line here is just making sure that admin is not a selectable group and then it's returning the group selected array that we pushed from there so it's going to only return the groups that they're in so that they can be removed it won't let you try to remove someone from a group that they're not in and looking at the next variable it's pretty much the opposite so same thing here we've got the script include the function and then what we're going to give to the function and exact same script just for simplicity's sake and you could always combine this into one script into one function on the same script i just split it up to make the example a little bit more clear so same thing here only difference is we're going to be returning the groups they're not in so that they can be added so it won't return any groups that they are already in only the ones they're not in so again this is the advanced reference qualifier so now that we've gone over that we'll go over the last example which is the dynamic reference qualifier so the dynamic reference qualifier is essentially the same as an advanced reference qualifier it's just reusable they still require that initial setup where you set up the script include and the function but they're easier to reuse if you have multiple variables which you wish to use the exact same advanced reference qualifier so we'll go ahead and look an example of that so same thing here i did use similar to the previous example just to make it a little bit easier to understand so this field here we can select a user and what it will do is return all the groups that they're not in so that you can add them to those groups so you can see the results are different each time all right and now we'll go to the variable take a look at this of what's different in a dynamic versus an advanced so same thing you're going to have a some type of reference field selected in your type specifications you're going to select your table here that you're referencing now in this you're going to select dynamic and what that's going to do is populate this field it's not going to populate the field but it will show this field which you can populate yourself so this is where you're selecting the dynamic reference qualifier and where this table is coming from so you can see here is pulling off the dynamic filter options table so we'll go ahead and look at that so that was user groups so we're on that table here this is the dynamic filter so looking at that using you can see here is the name of it here is where you would set up that same script include and function that you did for the advanced reference qualifier here so you can see we're calling that script include with the function and the variable that we're feeding it now obviously when you're using a dynamic reference qualifier you're going to want to try to make your variables as general as possible because the more specific it is the more specific it's going to be in its use case now the only difference in this field versus the other one as you can see you do not need to prefix javascript to your script include after you put it in this this field here and then you're going to select your reference table right here and why that's important is we'll go back to our variable page here if you select a different table you're actually going to get different dynamic filters so let's just choose this table clear this out and let's search that table so as you can see there's no dynamic filters on this sys graphql type resolver table so if we want to use that user group the user groups dynamic filter that we created earlier we're going to need to go to the sys user table so we'll go ahead and put that back in and we'll watch that change gotta find the table there it is so now that we're on that table again so that's actually let's just use a group table my mistake all right now that we have the correct table selected we'll go back here and check and as you can see there was our dynamic filter so we can select that so again the main difference between an advanced reference qualifier and a dynamic one is after you set up a dynamic reference qualifier on the dynamic filters options table you can reuse that anytime you select dynamic reference qualifier as long as your function and your script include take into account whatever item you're going to use it on or whatever variables it needs other than that i hope that this video made reference qualifiers a little bit more easy to understand hope you guys have a good one
https://www.youtube.com/watch?v=1QD9OA-Kx0M