Reference Qualifier
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:-
- 1) Simple 2) Dynamic 3) Advanced
2.1 How to Reach Reference Qualifier in OOB Table or Custom Table : - Open any Table of Your Choice: - Incident/Problem/Change.
- Step 1:-Application Navigator>Incident>Open Existing Record or Create New.
- Step 2:-Right Click on Any Reference Field i. e. Caller
- Step 3:-Configure Dictionary.
- 2.1 How to Reach Reference Qualifier in Service Catalog : - Open any Catalog Item from main item (sc_cat_item) Table
- Step 1 :- Open any your catalog item
- Step 2 :- Go to Related List and Open your Variables Tab
- Step 3 :- Open any Reference Type Variable
- Step 4 :- Check in Type Specification
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: (). <function name>()</strong> </p> <p>The function must return a query string that can filter the options available on a reference field.</p> <p>Please Follow the Syntax below:-</p> <p><img src="https://community.servicenow.com/community/image/serverpage/image-id/89658i10DF85C2240E1065/image-size/large?v=v2&px=999" alt="image"></p> <p>This is How we have we have seen the Journey so far about the Reference Qualifier.</p> <p>Now below I will adding the some scenarios which I came across during my profession career.</p> <p>also I will be adding some links which might be helpful for all of you to explore this topic more.</p> <p>Use of INSTANCEOF in Reference Qualifier:-</p> <p><strong>6.0 Use of INSTANCEOF operator in a reference qualifier:-</strong></p> <p>we can use the <strong>INSTANCEOF</strong> operator in a reference qualifier to shorten or simplify a complex class qualifier.</p> <p><a href="https://docs.servicenow.com/bundle/paris-platform-administration/page/script/server-scripting/concept/c%5FUseTheINSTANCEOFOperator.html" target="_blank" rel="noopener">Use of INSTANCEOF Operator</a></p> <p><strong>7.0 Scenario :-</strong></p> <p><strong>Scenario 1:-</strong></p> <p>We need all the Active users in Caller Field and all users must belong to IT Team only.(use Simple)</p> <p>Just add simple qualifier and use condition builder to filter these 2 fields.</p> <p><strong>Scenario 2:-</strong></p> <p>I want the VIP user available in Caller Field of Incident Table:-<br><br> You can use the Simple Variable with just add the Condition builder.</p> <p><strong>Scenario 3:-</strong></p> <p>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.</p> <p>department:function()</p> <p>{</p> <p>var gr=new GlideRecord('sys_user');</p> <p>gr.addQuery('sys_id',gs.getUserID()); gr.query();</p> <p>if(gr.next())</p> <p>{</p> <p>return "department"+"="+gr.department.toString();</p> <p>}</p> <p>},</p> <p><strong>Scenario 4 :-</strong></p> <p>Set a person who belongs to the same department as the applicant's department.</p> <p>getDepartmentUsers: function() {</p> <p>var userRec = new GlideRecord('sys_user');userRec.get(gs.getUserID());</p> <p>var department = userRec.getValue('department');</p> <p>var usersList = [];<br><br> var grUser = new GlideRecord('sys_user');</p> <p>grUser.addQuery('company', gs.getUser().getCompanyID()); grUser.addQuery('department', department);</p> <p>grUser.query();</p> <p>while(grUser.next()) { usersList.push(grUser.getUniqueValue());</p> <p>}</p> <p>return 'sys_idIN' + usersList;</p> <p>},</p> <p><strong>Scenario 5 :-</strong></p> <p>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.<br><br> department:function()</p> <p>{</p> <p>var gr=new GlideRecord('sys_user');</p> <p>gr.addQuery('sys_id',gs.getUserID());</p> <p>gr.query();</p> <p>if(gr.next()){</p> <p>return "department"+"="+gr.department.toString(); }</p> <p>},</p> <p><strong>Scenario 6 :-</strong></p> <p>Requirement to filter user in field Creator (Reference to sys_user), dependent group user login.</p> <p>createGroup :function() var grpcr;var usr=gs.getUserID();//get current logged in user Idvar usrarr=[];var groupss=new GlideRecord('sys_user_grmember');groupss.addQuery('user',usr);groupss.query();while(groupss.next()){ grpcr=groupss.group;</p> <p>}</p> <p><strong>Scenario 7 :-</strong></p> <p>select the Manager in 1 reference field, and his Manager (selected manager's) needed to be shown in other Reference Field.</p> <p>var var sys_id="";var gr=addNotNullQuery('manager');gr.query();while(gr.next()){ sysid=sysid+", "+gr.manager;}</p> <p>return ' sys_idIN'+sysid;</p> <p><strong>Scenario 8 :-</strong></p> <p>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; }</p> <p>return 'sys_idIN'+sysid;</p> <p><strong>Scenario 9 :-</strong></p> <p>The User wants to have Assignments Group Visible:-<br><br> Use below Reference Qualifiers</p> <p>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;</p> <p>}</p> <p><strong>8.0 Some Important Notes and Best Practices about Reference Qualifier:-</strong></p> <ul> <li>If You have added Reference Qualifier on variable set then it will not work on the variables outside the Variable Set or Vice Versa with Variables.</li> <li>Reference Qualifiers are only Applicable to Reference Fields or Reference Variables</li> <li>It is Best Practice to add Script Include instead of Global Business Rule in Reference Qualifiers.</li> </ul> <p><strong>9.0 Some Important Links of ServiceNow Community Experts :-</strong></p> <p><a href="https://community.servicenow.com/community?id=community%5Fquestion&sys%5Fid=76200761db98dbc01dcaf3231f9619f4&view%5Fsource=searchResult" target="_blank" rel="noopener">Refer 1</a></p> <p><a href="https://community.servicenow.com/community?id=community%5Fquestion&sys%5Fid=49f84976db49e01011762183ca96196b&view%5Fsource=searchResult" target="_blank" rel="noopener">Refer 2</a></p> <p><a href="https://servicenowguru.com/scripting/script-includes-scripting/advanced-reference-qualifier-script-include/" target="_blank" rel="noopener">Refer 3</a></p> <p><a href="https://community.servicenow.com/community?id=community%5Fquestion&sys%5Fid=3c9bc424db2258107d3e02d5ca96193f&view%5Fsource=searchResult" target="_blank" rel="noopener">Refer 4</a></p> <p><strong>10.0 Videos to kick start this Topic:-</strong> </p> <p><a href="https://www.youtube.com/watch?v=I7ZNPyrWCuU" target="_blank" rel="noopener">Chuck Tomasi</a></p> <p><a href="https://www.youtube.com/watch?v=nCnZDUbM6XY" target="_blank" rel="noopener">Video 1</a></p> <p><a href="https://www.youtube.com/watch?v=6V1Vf-pk1wc&t=240s" target="_blank" rel="noopener">Video </a>2</p> <p>Link of my Another Article:-</p> <p><a href="https://community.servicenow.com/community?id=community%5Farticle&sys%5Fid=2750d18ddb85a0109e691ea6689619cc" target="_blank" rel="noopener">Uses of hasRole() Methods (client and server side)</a></p> <p>Please Mark Helpful to the Article , share it amongst all your colleague</p> <p>Thanks and Regards</p> <p>Gaurav Shirsat</p> <p><a href="https://community.servicenow.com/now-platform/latest-release.html" target="_blank" rel="noopener"><img src="https://community.servicenow.com/community/s/html/assets/Xanadu-Community_Banner_1_314x314.jpg" alt="image"></a></p>
https://www.servicenow.com/community/itsm-articles/reference-qualifier/ta-p/2306509