Service Request Outbound - how to capture all variable answers and send JSON
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 06:58 PM - edited 02-20-2023 06:58 PM
Hi,
For the Service Request Integration, I need to capture the variables and variable set values / answers (dynamically based on the current catalog used by the user ) and pass JSon to another instance.
please help how we can capture the variables and variable set from catalog.
Thank you.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 07:48 PM
@Community Alums you can capture all variables and respective values of a RITM from table 'sc_item_option_mtom' with filtering RITM in field parent request.
Do let me know if you needed code for this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 08:53 PM
@Community Alums
so what script did you start with and where are you stuck?
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-16-2023 03:56 AM
Hi ,
I have referred the below code and able to capture the values .
Example to access a multi-row variable set of GlideRecord for the Task table
var now_GR = new GlideRecord('sc_req_item'); now_GR.get('02c38dcd87013300e0ef0cf888cb0bb2'); var vars = now_GR.variables.getElements(true); for (var i=0; i<vars.length; i++) { var now_V = vars[i]; if (now_V.isMultiRow()) { var rows = now_V.getRows(); for (var j=0; j<now_V.getRowCount(); j++) { var row = rows[j]; var cells = row.getCells(); for (var k=0; k<cells.length; k++) { var cell = cells[k]; gs.info(cell.getLabel() + ":" + cell.getCellDisplayValue()) } } }
I was not aware how to capture MRVS variables and now it is clear .
Thank you for your response and i will post if anything required additional.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2023 10:36 PM - edited 02-20-2023 10:38 PM
If you have the record you can easily loop through the variables and build the object to pass on in the integration. Just be sure that if you use mulitrows it can be a bit complex. E.g:
var ritVars = rec.variables;
var varObjMrvs = {};
var varObj = {};
for (var r in ritVars) {
var varNow = r;
var varName = ritVars[r].toString();
if (ritVars[r].isMultiRow()) {
var mrvs = ritVars[r];
varObjMrvs[varNow] = JSON.parse(mrvs);
} else {
varObj[varNow] = ritVars[r].toString();
}
}
var jsonObj = {};
jsonObj.varObj = varObj;
jsonObj.objmrvs = varObjMrvs;
return jsonObj;