logo

NJP

Reference Qualifiers in ServiceNow

Import · Dec 17, 2023 · article

Reference qualifiers in ServiceNow are filters that restrict the data that appears in reference fields. They help refine the choices available in a reference field by defining conditions that the referenced records must meet.

Types of Reference Qualifiers:-

1. Simple Reference Qualifier:- A simple reference qualifier in ServiceNow is often written as an encoded query string or a GlideRecord query. It's used to filter the choices available in a reference field based on specific criteria. Here's an example of a simple reference qualifier: -

Suppose We are applying the Reference Qualifier on the Caller Field of the Incident Table.

Screenshot 2023-12-16 at 4.01.21 PM.png

Here we are using the Simple Reference Qualifier where the condition is When Location is India.

It will only show the User in the Caller Field whose Location is India.

2. Dynamic Reference Qualifier:- It dynamically changes references or qualifiers based on user input into the fields of the current form.

Here's an example of a dynamic reference qualifier: -

Use Reference Qualifier - Dynamic

Dynamic ref qual - Create New Dynamic Filter Options

In the Script:-

return "location=" + current.location;

Suppose we have a field on the Incident table called Location.

We want to show/filter the users in the caller field whose location is the same as the Value of Location in the Incident Form.

3. Advanced Reference Qualifier:- Advanced Reference Qualifiers" refer to a mechanism that allows you to dynamically filter and restrict the data that appears in reference fields on forms.

Here's an example of an Advanced reference qualifier: -

Use Reference Qualifier - Advanced

Reference qual:- javascript: new myScriptInclude.myNewFunction();

myScriptInclude // Script Include Name

myNewFunction() // Script Include Function Name

Scenario :-

We want the users to show/filter users in the caller field, who are in the Same department of the logged-in user.

var myScriptInclude = Class.create();
myScriptInclude.prototype = {
    initialize: function() {},

    myNewFunction: function() {
        var gr = new GlideRecord('sys_user');
        gr.get(gs.getUserID()); // It will find the record of Logged In user in User table.
        var department = gr.getValue('department');

        var users = new GlideRecord('sys_user');
        gr.addQuery('department', department);
        gr.query();
        var refUsers = [];

        while (gr.next()) {
            refUsers.push(gr.getUniqueValue());
        }

        return 'sys_idIN' + refUsers;

    },

    type: 'myScriptInclude'
};

==========================================================================================================

If you find the article helpful, Please give me thumbs up on it :thumbs_up: :smiling_face_with_smiling_eyes:.

Happy Learning :slightly_smiling_face:

View original source

https://www.servicenow.com/community/developer-articles/reference-qualifiers-in-servicenow/ta-p/2765175