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.

Multirow Variable Set returning backend values after submitting "Add" button

Deepthi13
Tera Expert

Hi Team,

I am facing issue where multirow variable set returning backend values after clicking on Add on the form.  like below.
I am adding add option by splitting the response body from script include.

Deepthi13_0-1726133836564.png

 

Deepthi13_2-1726133931401.png

sdnd alert is what getting response from script include: BFS Operations LLB - 1110,BFS Group LLC (DE) - 1120,BFS Texas Sales LLC - 1130,BFS Texas Sales LLC - 1140,Spenard Builders AK - 1150,BFS Sales DC - 10,Plant Transfers DC - 20,BFS Common Division - 10

Client script:

function onLoad() {
    var ga = new GlideAjax("OMNIUtils");
    ga.addParam("sysparm_name", "getSDCD");
    ga.getXML(getResponse);
    function getResponse(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
        var sdnd = answer.toString().split("#@#");
        alert(sdnd);
        var salesOrgs = sdnd[0].split(",");
        var dNames = sdnd[1].split(",");
        var divisions = sdnd[2].split(",");
        for (var i = 0; i < salesOrgs.length; i++) {
            g_form.addOption('salesarea', salesOrgs[i].split(" - ")[1], salesOrgs[i].split(" - ")[0]);
        }
        for (var j = 0; j < dNames.length; j++) {
            g_form.addOption('distributionchannel', dNames[j].split(" - ")[1], dNames[j].split(" - ")[0]);
        }
        for (var k = 0; k < divisions.length; k++) {
            g_form.addOption('dname', divisions[k].split(" - ")[1], divisions[k].split(" - ")[0]);
        }
    }
}

Script include:

 getSDCD: function() {
        // Sample data similar to what you provided
        var request = new sn_ws.RESTMessageV2('OMNIapi', 'SalesAreaAssignments');
        var response = request.execute();
        var data = JSON.parse(response.getBody());
        // Extracting unique values for SalesOrgName, DChannelName, and DivisionName
        var salesOrgNames = this.getUniqueValues(data, 'SalesOrgName', "SalesOrg");
        var dChannelNames = this.getUniqueValues(data, 'DChannelName', 'DChannel');
        var divisionNames = this.getUniqueValues(data, 'DivisionName', "Division");
        return salesOrgNames.join(',') + "#@#" + dChannelNames.join(',') + "#@#" + divisionNames.join(',');
    },

 

 

2 REPLIES 2

Deepthi13
Tera Expert
answer =

"BFS Operations LLB - 1110,BFS Group LLC (DE) - 1120,BFS Texas Sales LLC - 1130,BFS Texas Sales LLC - 1140,Spenard Builders AK - 1150#@#BFS Sales DC - 10,Plant Transfers DC - 20#@#BFS Common Division - 10"

Mani A
Tera Guru

Make sure sales area,distChanrl,dname variable should be available on form.

 

function onLoad() {

    var ga = new GlideAjax("OMNIUtils");

    ga.addParam("sysparm_name", "getSDCD");

    ga.getXML(getResponse);

 

    function getResponse(response) {

        var answer = response.responseXML.documentElement.getAttribute('answer');

        var sdnd = answer.toString().split("#@#");

 

        // Ensure the sdnd array has expected length

        if (sdnd.length !== 3) {

            gs.error("Unexpected response format: " + answer);

            return;

        }

 

        var salesOrgs = sdnd[0].split(",");

        var dNames = sdnd[1].split(",");

        var divisions = sdnd[2].split(",");

 

        // Ensure fields exist before adding options

        if (g_form.getControl('salesarea')) {

            for (var i = 0; i < salesOrgs.length; i++) {

                var parts = salesOrgs[i].split(" - ");

                if (parts.length === 2) {

                    g_form.addOption('salesarea', parts[1], parts[0]);

                }

            }

        }

 

        if (g_form.getControl('distributionchannel')) {

            for (var j = 0; j < dNames.length; j++) {

                var parts = dNames[j].split(" - ");

                if (parts.length === 2) {

                    g_form.addOption('distributionchannel', parts[1], parts[0]);

                }

            }

        }

 

        if (g_form.getControl('dname')) {

            for (var k = 0; k < divisions.length; k++) {

                var parts = divisions[k].split(" - ");

                if (parts.length === 2) {

                    g_form.addOption('dname', parts[1], parts[0]);

                }

            }

        }

    }

}