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

Ankur Bawiskar
Tera Patron
Tera Patron

@matthew_hughes 

what debugging have you done so far?

you need to check if value is present or not

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

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;
aps_value.push(row);
}
return JSON.stringify(aps_value);
},

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks @Ankur Bawiskar  I've tried that and now the following weird behaviour is happening:

matthew_hughes_0-1735829104089.png

 

When I select a Lab after selecting my New Platform, the Platform field is set to Null

 

 

When I select a New Platform, the Platform field is set to Null:

matthew_hughes_2-1735829233377.png

 

matthew_hughes_1-1735829200389.png

 

@matthew_hughes 

handle the same logic for that variable

Check if value is present or not and if yes then only set the value

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

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@matthew_hughes 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader