We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Setting Reference Qualifier through Client Script on List Collector Variable

tiguin2798
Tera Guru

Hello,

 

I am currently building a catalog item where I have a need to pull a list of servers in a list collector variable as this selection could be multiple choice. The issue is I need this list to filter based off the selections of two other variables. I have tried setting this field to basically pull nothing through a simple reference qualifier so it would not cause long loading times on the catalog as it tries to pull thousands of items from cmdb_rel_ci (pulling the child server).

Because I am pulling a reference from cmdb_rel_ci what I am trying to do is have a variable "application_name" that is from the "cmdb_ci_business_app" (same as "parent" on "cmdb_rel_ci") table and "server_types" that is pulling from "sys_db_object" for the Class name.

 

I basically need "server_name_s" (child server) to populate options where "application_name" is the parent (the display name not the sys_id of the record) and the "server_types" are the class.

 

Is it possible to set a reference qualifier through an "onChange" client script or does this need to be done in an advanced reference qualifier? I have tried that as well and that does not seem to work also.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {  
      return;
   }

    //stores application_name sysID and pulls server names by parent sysID which is the application_name variable referenced

   var appName = g_form.getDisplayValue('application_name');
   var serverTypes = g_form.getDisplayValue('server_types');

   if (!appName || !serverTypes) {
      g_form.clearValue('server_name_s');
   }
   
   var refQual = 'parent.name=' + appName + '^child.sys_class_nameIN' + serverTypes;
   
   g_form.setReferenceQual('server_name_s', refQual);
}
4 REPLIES 4

yashkamde
Kilo Sage

Hello @tiguin2798 , 

try passing sys_id's in refQual i.e try using .getValue instead of display value..

I had tried this and this was not working as well. For "application_name" this is a reference to the "cmdb_ci_business_app" table but on "cmdb_rel_ci" table "parent" (matches "application_name") is a string vs a sys_id record.

Brad Bowman
Kilo Patron

An advanced reference qualifier is a better approach.  Be certain that you also add a Variable attribute like

ref_qual_elements=var_1;var_2

Post your attempt if it's still not working.

Chaitanya ILCR
Giga Patron

HI @tiguin2798 ,

if your list collector is referencing cmdb_rel_ci

try this

javascript:'parent=' + current.variables.application_name + '^child.sys_class_nameIN' + current.variables.server_types;

ChaitanyaILCR_0-1769013182272.png

 

if it's referencing the server table try this

ChaitanyaILCR_1-1769013251212.png

 

javascript:(function() {
    var arr = [];

    var relGr = new GlideRecord('cmdb_rel_ci');
    relGr.addEncodeQuery('parent=' + current.variables.application_name + '^child.sys_class_nameIN' + current.variables.server_types);
    relGr.query();
    while (relGr.next()) {
        arr.push(relGr.getValue('child'));
    }
    return 'sys_idIN' + arr.join();

})();

 

 variable attributes used based on your variables names from you script on which the list collector is dependent on

ref_qual_elements=application_name;server_types

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya