Service Request Outbound - how to capture all variable answers and send JSON

Community Alums
Not applicable

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.

4 REPLIES 4

Abhay Kumar1
Giga Sage

@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.

Ankur Bawiskar
Tera Patron
Tera Patron

@Community Alums 

so what script did you start with and where are you stuck?

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

Community Alums
Not applicable

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. 

 

ivaroen
Tera Expert

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;