Variables in multi-row to be sent via REST API

amamd
Tera Contributor

UPDATE : There is a 'Variable Set' on a request catalog which only includes a multi row table containing 5 fields that will have 5 rows of info in it. looking to send those variable values to a third party application using REST API. 

Need help is below script which will be added in the workflow to send the values of up to 5 rows (could be 1 to 5 rows ).Any help is appreciated.

Below has been tested successfully in the Rest API HTTP Method test.

{
"input_vars": {
      "Template": [{
           "number": "1",
           "perh": "1",
           "ear": "1",
           "file": "1",
           "day": "1",

},

{
           "number": "2",
           "perh": "2",
           "ear": "2",
           "file": "2",
           "day": "2",

}

--------------------------------------------------------

 

var gr = new GlideRecord(current.sys_id);
var mrvs = new GlideMultipleRowVariableSet().get(current, 'MultiRow_VARSET');
var variables = [];
for (var i = 0; i < mrvs.getSize(); i++) {
var row = mrvs.getRow(i);
var obj = {};
obj.var1 = row.number.toString();
obj.var2 = row.perh.toString();
obj.var3 = row.ear.toString();
obj.var4 = row.file.toString();
obj.var5 = row.day.toString();

variables.push(obj);
gs.log('TEST ' + mrvs + 'Rows == ' + rowCount);
gs.log("variables " + obj);
}
 var json = JSON.stringify(obj);
var rm, response, status, responseBody, errorMsg;
try {

var r = new sn_ws.RESTMessageV2('Restcall', 'POST');
// r.setStringParameterNoEscape('messageBody', JSON.stringify(Data));
r.setRequestBody(json);
response = r.execute();
status = response.getStatusCode();
responseBody = response.getBody();
errorMsg = response.haveError() ? response.getErrorMessage() : '';
} catch (ex) {
errorMsg = ex.getMessage();
status = '500';

---------------------------------------------------------------------

 

 

 

 

amahmed_0-1678890056848.png

 

8 REPLIES 8

Getting error in the logs, 

where to check for the output json ?

 

amahmed_0-1679295649052.png

 

@amamd 

this class is the issue -> GlideMultipleRowVariableSet

don't use it. use another way to obtain MRVS values

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

Thanks. Can you kindly suggest a different way and is syntax or a link where it is expalined.

@amamd 

check this link

https://www.servicenow.com/community/developer-forum/get-values-from-mrvs/m-p/1864581 

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