Generate a filtered list based on another field (client script, script include)

dimitar4
Kilo Explorer

Hi All,

On Catalog item I want to define a reference list on a variable field based on something selected on a previous field.

So. If I chose an option on field A I want to provide a specific filter on field B.

Ive done this via an onChange client script that fires off the value of field A to a script include and sends back to client script to then filter the reference list in field B.

The client script getting the value, sending to the SI and running the query works as intended. The sending back and filtering the list is NOT.

see client script:

-----------------------------------

function onChange(control, oldValue, newValue, isLoading) {

      if (newValue != oldValue) {      

              var catalogHelper = new GlideAjax("FRUCatalogVariablesHelper");

              catalogHelper.addParam("sysparm_name", "serverList");

              catalogHelper.addParam("sysparm_server", g_form.getValue('technical_infrastructure'));

              catalogHelper.getXMLWait();

var answer = catalogHelper.getAnswer();

                g_form.setValue('virtual_server',answer);

                      }

}

-------------------------------------

see script include:

--------------------------

var FRUCatalogVariablesHelper = Class.create();

FRUCatalogVariablesHelper.prototype = Object.extendsObject(AbstractAjaxProcessor, {

      serverList : function() {

              var server = this.getParameter('sysparm_server');

              if (server == 'vm_aix'){

                      var vgr = new GlideRecord('cmdb_ci_server');

                      vgr.addQuery('u_operating_system_family', 'AIX');

                      vgr.addQuery('active', true);

                      vgr.query();

                     

                      while (vgr.next()) {

                            var filter = '^ORu_operating_system_family=' + 'AIX';

                                              return filter;

                      }

              }

              },

      type: 'FRUCatalogVariablesHelper'

});

------------------------------

Any help much appreciated 🙂

1 ACCEPTED SOLUTION

venkatiyer1
Giga Guru

Hi Dimitar,




This link would be useful for you. You might want to call a script include on the reference qualifier to get a list and return the list as in 'sys_idIN' + returnedList



Reference Qualifiers - ServiceNow Wiki



Also, may be you can call the FRUCatalogVariablesHelper only if the newValue or changed value is vm_aix so that you can avoid a unnecessary server call as there is no else condition to support it otherwise.


View solution in original post

1 REPLY 1

venkatiyer1
Giga Guru

Hi Dimitar,




This link would be useful for you. You might want to call a script include on the reference qualifier to get a list and return the list as in 'sys_idIN' + returnedList



Reference Qualifiers - ServiceNow Wiki



Also, may be you can call the FRUCatalogVariablesHelper only if the newValue or changed value is vm_aix so that you can avoid a unnecessary server call as there is no else condition to support it otherwise.