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.

How to get the returned value to client script

Anna_Servicenow
Tera Guru

I have the below script, How can I get the value back to client script and set it in form section

var AttachmentParse = Class.create();
AttachmentParse.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    process: function() {
        var currentSysId = this.getParameter('sysparm_sys_id');
        gs.log("currentSysId: " + currentSysId);
        var attachment = new GlideSysAttachment();
        var getdata = new GlideRecord('sys_attachment');
        getdata.addQuery('table_sys_id', currentSysId);
        getdata.addQuery('table_name', "ZZ_YYu_bpm");
        getdata.query();
        if (getdata.next()) {
            gs.log("loop");
            var attachmentSysID = getdata.sys_id.toString();
            var attachmentStream = attachment.getContentStream(attachmentSysID);

            var demodata = new sn_impex.GlideExcelParser();
            demodata.parse(attachmentStream);

            var caseID = [];
            var resolvedBy = [];
            var headers = demodata.getColumnHeaders();
            var header1 = headers[0];
            var header2 = headers[1];
            while (demodata.next()) {
                var row = demodata.getRow();
                caseID.push(row[header1]);
                resolvedBy.push(row[header2]);
            }
            gs.info("Case ID: " + caseID);
            gs.info("Resolved By: " + resolvedBy);
3 REPLIES 3

Anurag Tripathi
Mega Patron
Mega Patron

I think your issue is you have 2 Array and how to return them both 

You can make array or Array or JSON here

Eg

 

var AttachmentParse = Class.create();
AttachmentParse.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    process: function() {
        var currentSysId = this.getParameter('sysparm_sys_id');
        gs.log("currentSysId: " + currentSysId);
        var attachment = new GlideSysAttachment();
        var getdata = new GlideRecord('sys_attachment');
        getdata.addQuery('table_sys_id', currentSysId);
        getdata.addQuery('table_name', "ZZ_YYu_bpm");
        getdata.query();
        if (getdata.next()) {
            gs.log("loop");
            var attachmentSysID = getdata.sys_id.toString();
            var attachmentStream = attachment.getContentStream(attachmentSysID);

            var demodata = new sn_impex.GlideExcelParser();
            demodata.parse(attachmentStream);

            var caseID = [];
            var resolvedBy = [];
var finalArr = [];
            var headers = demodata.getColumnHeaders();
            var header1 = headers[0];
            var header2 = headers[1];
            while (demodata.next()) {
                var row = demodata.getRow();
                caseID.push(row[header1]);
                resolvedBy.push(row[header2]);
            }
finalArr[0] = caseID.toString();
finalArr[1] = resolvedBy.toString();
            gs.info("Case ID: " + caseID);
            gs.info("Resolved By: " + resolvedBy);
return finalArr;
}
}

 

-Anurag

 

I could get the value in client script, how can I set it to form section like below. ( we have this in place already and we enter the value manually, now I want the returned value to be set here automatically.) @Anurag Tripathi 

 

Anna_Servicenow_0-1734632085439.png

 

Hey Ana, This is an embedded list, which means this data is on another table and has a reference to current table.

You can't add or modify data here through client script. 

I would suggest you do this on the script include itself writing a GlideRecord on this table and updating the record.

On the client script you can just reload the form.

-Anurag