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

Community Alums
Not applicable

Hi @Simo Shaf ,

Try this, it'll work.

 

var requestForCheckbox = g_form.getBooleanValue('user_not_visible')

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Simo Shaf 

requested_for is of what type? reference or list collector?

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

Hi @Ankur Bawiskar 
It is reference , see images please

@Simo Shaf 

then don't use onChange client script

Just use advanced ref qualifier on that reference variable

Ensure you give correct sysId of that territory you have selected

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

Hi @Ankur Bawiskar 
Thanks! But it doesn't work.