Empty field on catalogue item appearing as NULL on requested item

matthew_hughes
Kilo Sage

I've got a catalogue item that allows a user to not select a certain field and they can leave this empty:

matthew_hughes_0-1735916652136.png

From the screenshot, the user can leave the New Lab Level/Platform Child field empty. However, when a user submits their request, it appears as NULL in the requested item rather than showing as empty:

matthew_hughes_1-1735916730125.png

 

I'm using a multi row variable set to get my results.  The following client scripts apply to the New Platform and New Lab Level/Platform Child fields:

matthew_hughes_2-1735916915878.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 == null){
            g_form.clearValue('new_lab_department');
        //}
        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_platform', g_form.getDisplayValue('new_platform'));
        }
        else{
            gr.addParam('sysparm_platform', "");
        }
        if(g_form.getValue('new_lab')!=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", []);
    }

}


matthew_hughes_3-1735916962568.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', "");
        }
        if(g_form.getValue('new_platform')!=null){
            gr.addParam('sysparm_platform', g_form.getDisplayValue('new_platform'));
        }
        else{
            gr.addParam('sysparm_platform', "");
        }
        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", []);
    }

}


matthew_hughes_4-1735917007839.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'));
        }
        else{
            gr.addParam('sysparm_platform', "");
        }
        if(g_form.getValue('new_lab_department') != 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", []);
    }

}


 

Does anyone know what I need to do to show New Lab Level/Platform Child field as an empty value on my requested item rather than null

8 REPLIES 8

Hello @matthew_hughes 

 

Directly updating the variable is not available in flow, but you can create a custom action (reusable) to update the variables.

Refer https://www.servicenow.com/community/now-platform-articles/set-value-of-a-catalog-variable-at-flow-d...

https://www.servicenow.com/community/now-platform-forum/flow-designer-update-a-catalog-variable/m-p/...

 

Thank you,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Hi @Ahmmed Ali I tried creating the action in the example, but it won't allow me to select affected variable within my multi row variable set

Hello @matthew_hughes 

 

You will need to create custom action particularly for your item, means have input as RITM sys_id. then in script activity, query RITM table and set variable value or you can query sc_multi_row_question_answer table and update accordingly.

 

Thank you,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

JenniferRah
Mega Sage
Mega Sage

If you change this line 

g_form.clearValue('new_lab_department');

to this

g_form.setValue('new_lab_department', '');

Does that make a difference?