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

Aman Kumar S
Kilo Patron

Thanks Aman.

 

this article worked for me:
How to modify Reference Qualifiers with Catalog Client Scripts – ServiceNow – ServiceNow Think (word...

 

 

and this is the onChange client script:

 

var resetFilter = 'active=true^nameISNOTEMPTY^emailISNOTEMPTY^EQ';
var dynamicFilter = g_form.getValue('your other text var holding encoded query').toString().trim();
var gg = g_list.get('your ref var name'); // GlideList2 object
gg.setQuery(newValue == '' ? resetFilter : dynamicFilter);

Riya Verma
Kilo Sage
Kilo Sage

Hi @Simo Shaf ,

Hope you are doing great.

 

To address your requirement, you can create a catalog client script that handles the behavior of the checkbox field and the reference field. The script will determine whether to apply the reference qualifier condition or remove it based on the state of the checkbox field.

Please refer to the code below:

 

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');
    } else {
        var condition = 'territory= Netherlands'; // Replace 'Netherlands' with your desired condition
        referenceField.setAttribute('glide_list_filter', condition);
    }
}

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Hi @Riya Verma 

Thanks! But it's the same, it doesn't work.