Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Remove the reference qualifier condition

Simo Shaf
Tera Contributor

Hallo,
I am trying to create a catalog client script. I have a checkbox field called 'user_not_visible' and a reference field called 'requested_for'. The reference field has a reference qualifier condition based on a field called 'Territory' to filter users based on their territory. When the checkbox is checked, I want to remove the reference qualifier condition and show all users in the reference field. However, the current script I have tried is not working as expected.
See images please
---------------------

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }
var requestForCheckbox = g_form.getValue('user_not_visible');
  var referenceField = g_form.getControl('requested_for');
 
  if (requestForCheckbox) {
    referenceField.removeAttribute('glide_list_filter');   
// or referenceField.removeAttribute('reference_qual');
 
  } else {
    var condition = 'territory= Netherlands'; //for ex
    referenceField.setAttribute('glide_list_filter', condition);
  }
}
13 REPLIES 13

@Simo Shaf 

It should work fine.

Please share what advanced ref qualifier you used along with screenshots.

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

@Simo Shaf 

you didn't replace the actual field name for territory which is on user table

please use that in your query. I just gave an example and mentioned you need to use correct field name

javascript: var query = ''; if(current.variables.user_not_visible.toString() == 'false') query = 'territoryField=sysId'; query;

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

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

ntera4sho1
Tera Contributor

Hi Simo,

 

Check this out and customize it to suite your need. I hope it gives you an idea. Location in my case can be Territory in your case or something but this just illustrates the concept.

 

Variables on the Catalog item:

ntera4sho1_0-1688394441857.png

 

Script include:

 

function GetUsers(userLocation, usersNotVisible) {
    if (usersNotVisible == "false" && userLocation != "") {
        var userList = [];
        var userGr = new GlideRecord("sys_user");
        userGr.addQuery("location", userLocation);
        userGr.addActiveQuery();
        userGr.query();
        while (userGr.next()) {
            userList.push(userGr.sys_id.toString());
        }
        return 'sys_idIN' + userList;
    } else {
        return "active=true"; //or whatever condition you want to apply
    }
}

 

 

Advanced ref qualifier on the Users field:

 

javascript:GetUsers(current.variables.user_location, current.variables.user_not_visible);

 

 

If it helps, please mark as correct. Thanks

 

Regards,

N