Variables in multi-row to be sent via REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 07:26 AM - edited 03-15-2023 11:07 PM
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';
}
---------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2023 12:02 AM
Getting error in the logs,
where to check for the output json ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2023 01:02 AM
this class is the issue -> GlideMultipleRowVariableSet
don't use it. use another way to obtain MRVS values
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2023 01:20 AM
Thanks. Can you kindly suggest a different way and is syntax or a link where it is expalined.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2023 01:59 AM
check this link
https://www.servicenow.com/community/developer-forum/get-values-from-mrvs/m-p/1864581
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader