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.

Column in Multi row variable set returning null despite the related field not being selected

matthew_hughes
Kilo Sage

I'm trying to develop a catalogue item uses multi row variable sets. Most of the columns on the catalogue item are populating correctly as required. However, I'm having an issue with one of the columns:

matthew_hughes_1-1735821042236.png

 

 

What I've noticed is that if select my option for a New Platform, the 'New Lab Level/Platform Child' column is immediately set to null, even though the option for my new Lab has not been selected. When trying to select a new Lab, the available options don't load.

 

My Script Include is:

var LBGGetApplicationDetails = Class.create();
LBGGetApplicationDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    existing_app_srvc: function() {
        var aps_value = [];
        var ci_sysid = this.getParameter('sysparam_ci_sysid');
        var ci_new_platform = this.getParameter('sysparm_platform');
        var ci_new_lab = this.getParameter('sysparm_lab');

        var grapp = new GlideRecord('cmdb_ci_business_app');
        grapp.addQuery('sys_id', 'IN', ci_sysid);
        grapp.query();
        while (grapp.next()) {
            var row = {
                'business_application_number_variable_set': grapp.number.toString(),
                'business_application_owner_variable_set': grapp.u_business_owner.getDisplayValue(),
                'business_application_name_variable_set': grapp.name.toString(),
                'current_business_owning_platform_variable_set': grapp.u_business_owning_division.getDisplayValue(),
                'new_platform_variable_set': ci_new_platform,
                'new_lab_level_platform_child_variable_set': ci_new_lab,
            };
            aps_value.push(row);
        }
        return JSON.stringify(aps_value);
    },

    type: 'LBGGetApplicationDetails'
});
 
 
 
There are two client scripts for the Lab field:
The below client script is an on change client script for the selected Lab:
matthew_hughes_2-1735821271770.png

 

 
function onChange(control, oldValue, newValue, isLoading) {
    //If form is loading, do nothing
    if (isLoading) {
        return;

    //If the list of Business Applications to update is cleared, clear the Multi Row variable set
    } else {
        var gr = new GlideAjax('LBGGetApplicationDetails');
        gr.addParam('sysparm_name', 'existing_app_srvc');
        gr.addParam('sysparam_ci_sysid', g_form.getValue('business_applications_to_update'));
        //gr.addParam('sysparam_u_business_owning_division', current_owning_platform);
        if(newValue != null){
            gr.addParam('sysparm_lab', g_form.getDisplayValue('new_lab_department'));
        }
        else{
            gr.addParam('sysparm_lab', '');
        }
        gr.getXML(parseScript);
    }
}

function parseScript(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    var arr = JSON.parse(answer);
    if (arr.length > 0) {
        g_form.setValue("selected_business_applications", answer);
    } else if (arr.length == 0) {
        g_form.setValue("selected_business_applications", []);
    }

}


The below client script is an on change client script for the selected Business Applications:

matthew_hughes_3-1735821349576.png

 

function onChange(control, oldValue, newValue, isLoading) {
    //If form is loading, do nothing
    if (isLoading) {
        return;

    //If the list of Business Applications to update is cleared, clear the Multi Row variable set
    } else if (newValue == '') {
        g_form.setValue('selected_business_applications', []);
   
    //Each time a Business Application is added, add a row for each Business Application with the other variables
    } else {
        var gr = new GlideAjax('LBGGetApplicationDetails');
        gr.addParam('sysparm_name', 'existing_app_srvc');
        gr.addParam('sysparam_ci_sysid', newValue);
        //gr.addParam('sysparam_u_business_owning_division', current_owning_platform);
        if(g_form.getValue('new_platform') != null){
            gr.addParam('sysparm_platform', g_form.getDisplayValue('new_platform'));
        }
        if(g_form.getValue('new_lab_department') != null){
            gr.addParam('sysparm_lab', g_form.getDisplayValue('new_lab_department'));
        }
        gr.getXML(parseScript);
    }
}

function parseScript(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    var arr = JSON.parse(answer);
    if (arr.length > 0) {
        g_form.setValue("selected_business_applications", answer);
    } else if (arr.length == 0) {
        g_form.setValue("selected_business_applications", []);
    }

}


5 REPLIES 5

Hi @Ankur Bawiskar I've changed my script include to the following:

var LBGGetApplicationDetails = Class.create();
LBGGetApplicationDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    existing_app_srvc: function() {
        var aps_value = [];
        var ci_sysid = this.getParameter('sysparam_ci_sysid');
        var ci_new_platform = this.getParameter('sysparm_platform');
        var ci_new_lab = this.getParameter('sysparm_lab');

        var grapp = new GlideRecord('cmdb_ci_business_app');
        grapp.addQuery('sys_id', 'IN', ci_sysid);
        grapp.query();
        while (grapp.next()) {
            var row = {
                'business_application_number_variable_set': grapp.number.toString(),
                'business_application_owner_variable_set': grapp.u_business_owner.getDisplayValue(),
                'business_application_name_variable_set': grapp.name.toString(),
                'current_business_owning_platform_variable_set': grapp.u_business_owning_division.getDisplayValue(),
                //'new_platform_variable_set': ci_new_platform,
                //'new_lab_level_platform_child_variable_set': ci_new_lab,
            };

            if (ci_new_lab) // check here if it's there and remove it from above
                row['new_lab_level_platform_child_variable_set'] = ci_new_lab;



            if (ci_new_platform) // check here and remove from above
                row['new_platform_variable_set'] = ci_new_platform;
            aps_value.push(row);
        }
        return JSON.stringify(aps_value);
    },

    type: 'LBGGetApplicationDetails'
});
 
However, the behaviour is strange now because if I select a new platform and then a lab, the new platform field gets cleared out:
matthew_hughes_0-1735893486935.png

If I then select a new platform straight after, it doesn't populate the new entry within the multi variable set:

 

matthew_hughes_1-1735893576733.png