The Now Platform® Washington DC release is live. Watch now!
on ‎05-23-2021 09:25 AM
Reference Qualifiers
1.0 Reference Qualifier:-
Reference Qualifiers are to create filters that restrict the data that is returned for a reference field. A reference field stores a link (reference) to a field on another table, making the records/fields in the referenced table available to the form containing the reference field. Reference qualifiers are a powerful tool that every Service Now administrator and consultant should have in their tool belt. They allow you to dynamically filter the available options from a reference field.
Example :- Caller, Assigned To field on Incident Table which refers to User [sys_user] table.
Reference Qualifier in ServiceNow
2.0 Types of Reference Qualifiers:-
2.1 How to Reach Reference Qualifier in OOB Table or Custom Table : - Open any Table of Your Choice: - Incident/Problem/Change.
3.0 Simple Reference Qualifiers: - Simple reference qualifiers use AND/OR statements (conditions) to create simple filters. Use simple reference qualifiers when filtering on conditions such as whether a company is active, a user has a specific role, and/or a caller is in a specific time zone. Simple reference qualifiers can have a maximum of 13 reference qualifier conditions.
3.1 Please Check below:-
4.0 Dynamic Reference Qualifier:-Dynamic reference qualifiers enable you to use a dynamic filter option to run a query against a reference field to filter the returned data set. Dynamic filter options are stored filters that can contain encoded query strings, JavaScript, or script includes, and can be used in multiple dynamic reference qualifiers. Changes made to a dynamic filter option automatically apply to all reference qualifiers that use the same dynamic filter option. Use this type of reference qualifier when you want to use the same filter on multiple forms or to provide filter functionality to "non-code savvy" implementers. The base instance provides several OOB dynamic filter options. If a dynamic filter option that meets your needs does not exist, you can create a new dynamic filter option that is specific to your requirements.
All the available dynamic filters are stored in system definition>dynamic filter options.
For creating the dynamic reference qualifier we must have a record in this dynamic filter options.
After creating the dynamic reference qualifier you can add that filter from the Dynamic ref qual field.
It is Best Practice to add Script Include instead of Global Business Rule in Reference Qualifiers.
5.0 Advanced Reference Qualifier: - Advanced reference qualifiers enable you to define an inline encrypted query string or JavaScript (actual code or the name of an existing script include or business rule) filter directly in the Reference qualified field of the reference qualifier. Similar to the other reference qualifier types, when the form loads, the filter is executed, and only the records that match the filter appear in the reference field. Use this type of reference qualifier for implementations that only require a simple, unique filter that cannot be handled by a simple reference qualifier, and is not used across multiple reference fields.
In the reference qualifier we have lots of techniques to add filter:-
We can directly addQuery here like active=ture
One more way is to add JavaScript filters such as javascript: 'u_active=true^' + "u_hr_service="+current.hr_service in reference qualifiers.
We can call server side script include in advance reference qualifier:- syntax is
javascript: <script>(). <function name>()
The function must return a query string that can filter the options available on a reference field.
Please Follow the Syntax below:-
This is How we have we have seen the Journey so far about the Reference Qualifier.
Now below I will adding the some scenarios which I came across during my profession career.
also I will be adding some links which might be helpful for all of you to explore this topic more.
Use of INSTANCEOF in Reference Qualifier:-
6.0 Use of INSTANCEOF operator in a reference qualifier:-
we can use the INSTANCEOF operator in a reference qualifier to shorten or simplify a complex class qualifier.
7.0 Scenario :-
Scenario 1:-
We need all the Active users in Caller Field and all users must belong to IT Team only.(use Simple)
Just add simple qualifier and use condition builder to filter these 2 fields.
Scenario 2:-
I want the VIP user available in Caller Field of Incident Table:-
You can use the Simple Variable with just add the Condition builder.
Scenario 3:-
When we click on Caller Field, we must get reflected as per current logged in user. If user belongs to IT Team then user from IT Team Must gets displayed when we click on look up Icon.
department:function()
{
var gr=new GlideRecord('sys_user');
gr.addQuery('sys_id',gs.getUserID()); gr.query();
if(gr.next())
{
return "department"+"="+gr.department.toString();
}
},
Scenario 4 :-
Set a person who belongs to the same department as the applicant's department.
getDepartmentUsers: function() {
var userRec = new GlideRecord('sys_user');
userRec.get(gs.getUserID());
var department = userRec.getValue('department');
var usersList = [];
var grUser = new GlideRecord('sys_user');
grUser.addQuery('company', gs.getUser().getCompanyID());
grUser.addQuery('department', department);
grUser.query();
while(grUser.next()) {
usersList.push(grUser.getUniqueValue());
}
return 'sys_idIN' + usersList;
},
Scenario 5 :-
I have a couple of Reference Fields. If I click on the look up icon I want the data to be populated depending on some filters or query..and every user can see data depending on his category.
department:function()
{
var gr=new GlideRecord('sys_user');
gr.addQuery('sys_id',gs.getUserID());
gr.query();
if(gr.next()){
return "department"+"="+gr.department.toString(); }
},
Scenario 6 :-
Requirement to filter user in field Creator (Reference to sys_user), dependent group user login.
createGroup :function()
var grpcr;
var usr=gs.getUserID();//get current logged in user Id
var usrarr=[];
var groupss=new GlideRecord('sys_user_grmember');
groupss.addQuery('user',usr);
groupss.query();
while(groupss.next())
{
grpcr=groupss.group;
}
Scenario 7 :-
select the Manager in 1 reference field, and his Manager (selected manager's) needed to be shown in other Reference Field.
var var sys_id="";
var gr=addNotNullQuery('manager');
gr.query();
while(gr.next())
{
sysid=sysid+", "+gr.manager;
}
return ' sys_idIN'+sysid;
Scenario 8 :-
select the Manager in 1 reference field, and his (selected manager's) related members only needed to be shown in other Reference Field.
var var sys_id="";
var gr=addNotNullQuery('manager',manager);
gr.query();
while(gr.next())
{
sysid=sysid+", "+gr.manager;
}
return 'sys_idIN'+sysid;
Scenario 9 :-
The User wants to have Assignments Group Visible:-
Use below Reference Qualifiers
function getCaseGroups() {
var groupNames = "Accounts Receivable _ JIB, Revenue, Division Order, Payables, Regulatory, Production Reporting, Lease and Contracts Information, Land and Operations, SCOR Customer Care Center";
return groupNames;
}
8.0 Some Important Notes and Best Practices about Reference Qualifier:-
9.0 Some Important Links of ServiceNow Community Experts :-
10.0 Videos to kick start this Topic:-
Video 2
Link of my Another Article:-
Uses of hasRole() Methods (client and server side)
Please Mark Helpful to the Article , share it amongst all your colleague
Thanks and Regards
Gaurav Shirsat
Thank You
Nice One Gaurav 🙂
well explained. Great help through this article 🙂
Thanks a lot Pranav
useful information...thank you
Thank yo
Helpful..
Thanks Gaurav, I love it
very informative and helpful
very helpful
Thanks for this support..This is really helpful đź‘Ť
Nice Explained, really useful content.
Really Helpful
Thank you, very very useful !
Nice! Once place for all related stuff.
Really Helpful
well explained.
Very well explained.
A greatly detailed article, Gaurav!
very Helpfull
Thankyou @Gaurav Shirsat Greatful to see the content like this.
Thank you for this! Wonderfully explained. Also, can you let me know where can I find these type of real-time scenarios to understand Client Scripts, BRs etc?
Hello @Lavanya R1
First Things First, Your PDI is your good Tutor. Open your PDI you will find many Business Rules, Client Scripts, Script Includes Out of the Box.
Go through them, analyze them and learn.
post that each day, there are thousands of question of community and new UI of Community helps you to filter things. try those use cases.
You can reach out to me in case you need any help.
Gaurav Shirsat : ServiceNow Community MVP 2022
https://www.linkedin.com/in/gauravshirsat/
@Gaurav Shirsat Thank you, the content was very helpful
Thank you for this