Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

Reference qualifier to filter entitlements based on user country

Ankita9793
Tera Contributor

Hi All,

 

I want to display entitlements based on lob and category field selection. These entitlements are coming from u_platform_region table. I have used a advanced reference qualifier with below query which is working fine. 

Condition :  'u_domain ='+ current.variables.lob+ '^u_requesttype ='+current.variables.category;

 

The new requirement is to include below condition as well along with current condition based on the user country

Excluding China not visible to China else visible to all
Including China visible to China
NA visible to all


Ankita9793_0-1785133098123.png

 

 

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron

@Ankita9793 

try this. enhance as per your requirement like picking country, sysids of the region if region is reference field etc

javascript: var query;
var grUser = new GlideRecord('sys_user');
if (grUser.get(gs.getUserID())) {
    var country = grUser.country.toString(); // Adjust if using a custom field like u_country
    query = 'u_domain=' + current.variables.lob +
        '^u_requesttype=' + current.variables.category;

    if (country == 'China') {
        query += '^u_regionINIncludingChina,NA';
    } else {
        query += '^u_regionINExcludingChina,NA';
    }
    query;
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

Tanushree Maiti
Tera Patron

Hi @Ankita9793 

 

Try this,

 

1: Create a Script Include

  • Name: EntitlementUtils
  • Client callable: Checked (true)

var EntitlementUtils = Class.create();

EntitlementUtils.prototype = {

    initialize: function() {},

    getEntitlements: function(lob, category) {

        var query = 'u_domain=' + lob + '^u_requesttype=' + category;

        var userRec = gs.getUser().getRecord();

        var userCountry = userRec.getValue('country');

        if (userCountry == 'China') {

            query += '^u_region=China';

        }

        else if (userCountry == 'Excluding China') {

            query += '^u_region!=China';

        }

        else {

            // 'Else visible to all' requirement -> Do not append any restriction

        }

 

        return query;

    },

 

    type: 'EntitlementUtils'

};

 

2: Configure the Variable Reference Qualifier

javascript: new EntitlementUtils().getEntitlements(current.variables.lob, current.variables.category);

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@Ankita9793 

try this. enhance as per your requirement like picking country, sysids of the region if region is reference field etc

javascript: var query;
var grUser = new GlideRecord('sys_user');
if (grUser.get(gs.getUserID())) {
    var country = grUser.country.toString(); // Adjust if using a custom field like u_country
    query = 'u_domain=' + current.variables.lob +
        '^u_requesttype=' + current.variables.category;

    if (country == 'China') {
        query += '^u_regionINIncludingChina,NA';
    } else {
        query += '^u_regionINExcludingChina,NA';
    }
    query;
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Tanushree Maiti
Tera Patron

Hi @Ankita9793 

 

Try this,

 

1: Create a Script Include

  • Name: EntitlementUtils
  • Client callable: Checked (true)

var EntitlementUtils = Class.create();

EntitlementUtils.prototype = {

    initialize: function() {},

    getEntitlements: function(lob, category) {

        var query = 'u_domain=' + lob + '^u_requesttype=' + category;

        var userRec = gs.getUser().getRecord();

        var userCountry = userRec.getValue('country');

        if (userCountry == 'China') {

            query += '^u_region=China';

        }

        else if (userCountry == 'Excluding China') {

            query += '^u_region!=China';

        }

        else {

            // 'Else visible to all' requirement -> Do not append any restriction

        }

 

        return query;

    },

 

    type: 'EntitlementUtils'

};

 

2: Configure the Variable Reference Qualifier

javascript: new EntitlementUtils().getEntitlements(current.variables.lob, current.variables.category);

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti