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.

Using Client script for reference qualifier

rfairley22
Tera Contributor

Hello all,

I'm running into a dilemma with my client script for a reference qualifier for a field. For example:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
 
    //Type appropriate comment here, and begin script below
    var filter = g_list.get('ms_what_is_the_sys_instance_name');
    filter.setQuery('sys_class_name=cmdb_ci_lit_server^operational_status=1^ref_cmdb_ci_lit_server.u_server_role=ms^NQsys_class_name=cmdb_ci_db_mssfl_instance^operational_status=1^install_status=1^u_used_for=');
g_form.getValue(variables.ms_environment.toString());
}
 
I'm needing it to filter out based on that reference qualifier and then based off of the selection on the (ms_environment) whether Ham, Yin, or Joe chosen
3 REPLIES 3

jMarshal
Mega Sage

You'll need to do the getvalue above the setquery if you want to leverage the content returned by getvalue. You'll also need to assign that value to a variable that you can add to the query string that you're setting to the filter.

So something like this:

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
 
    //Type appropriate comment here, and begin script below
    var filter = g_list.get('ms_what_is_the_sys_instance_name');
   g_form.getValue(variables.ms_environment.toString()); filter.setQuery('sys_class_name=cmdb_ci_lit_server^operational_status=1^ref_cmdb_ci_lit_server.u_server_role=ms^NQsys_class_name=cmdb_ci_db_mssfl_instance^operational_status=1^install_status=1^u_used_for=');
 
}
 
For the part where you said "You'll also need to assign that value to a variable that you can add to the query string that you're setting to the filter." I believed the field value that I'm looking for is in the query? Can you give an example?

Community Alums
Not applicable

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);