How to fetch the mrvs variables.

AnandKumar1
Tera Expert

Hi Team,

In MRVS I have list collector variable. Here in each row i can able to add more then 1 ci in the list collector. And through workflow i am passing that value to api.

 

Here, I am facing challenge for adding multiple rows. For instance, for row 1 if i add 3 ci in list collector i can able to fetch it.. 

AnandKumar1_0-1695379432565.png

 

then if add another row, then 1st row 2 record and 2nd row 1record means, then the values i am not able concardinate here. Can someone assist here how to do outloop to get values.

 

below are my script 

 

var source_name;

var mvrs = JSON.parse(current.variables.u_request_details);

var mvrsLength = mvrs.length;

gs.info("Anand API - FireFlow mvrsLength 1: " + mvrsLength);

for (var i = 0; i < mvrs.length; i++) {

var sourceCMBD = mvrs[i].source_cmdb;
gs.info("Anand  API - FireFlow SourceCMBD 2: " + sourceCMBD);

var sourceName = new GlideRecord('cmdb_ci');
var query = 'sys_id=' + sourceCMBD;
sourceName.addEncodedQuery(query);
sourceName.query();
while (sourceName.next()) {
source_name = sourceName.name;
}

 

And like below i am sending the payload to api. >>>>>>>>>>>>>>

 

var r1 = new sn_ws.RESTMessageV2('ANAND API - FireFlow', 'Fireflow Traffic Change Request');

r1.setStringParameterNoEscape('source_name', source_name);

r1.setMIDServer('************');
var response1 = r1.execute();
var responseBody1 = response1.getBody();
var httpStatus1 = response1.getStatusCode();

var parsedResponse2 = JSON.parse(responseBody1);

2 ACCEPTED SOLUTIONS

Vishal Birajdar
Giga Sage

Hi @AnandKumar1 

 

Can you try by updating below lines (highlighted in bold red)

 

//make it array or JSON object choice is yours - here taken as array

var source_name =[];

var mvrs = JSON.parse(current.variables.u_request_details);

var mvrsLength = mvrs.length;

gs.info("Anand API - FireFlow mvrsLength 1: " + mvrsLength);

for (var i = 0; i < mvrs.length; i++) {

var sourceCMBD = mvrs[i].source_cmdb;
gs.info("Anand  API - FireFlow SourceCMBD 2: " + sourceCMBD);

var sourceName = new GlideRecord('cmdb_ci');
var query = 'sys_idIN' + sourceCMBD;
sourceName.addEncodedQuery(query);
sourceName.query();
while (sourceName.next()) {
source_name.push(sourceName.name);  //push value in array
}

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

Brad Bowman
Kilo Patron
Kilo Patron

I'm not following exactly.  In your log are you getting the full and expected values for source_cmdb?  If not, there's an alternate approach to parsing an MRVS that I can give you.  Assuming you're getting this far for now, it looks like you would want to change your query to allow for multiple:

var query = 'sys_idIN' + sourceCMBD;

and then inside the while loop you need to push each value to an array rather than overwriting the same script variable:

var source_nameArr = [];
var mvrs = JSON.parse(current.variables.u_request_details);
var mvrsLength = mvrs.length;
gs.info("Anand API - FireFlow mvrsLength 1: " + mvrsLength);
for (var i = 0; i < mvrs.length; i++) {
    var sourceCMBD = mvrs[i].source_cmdb;
    gs.info("Anand  API - FireFlow SourceCMBD 2: " + sourceCMBD);
    var sourceName = new GlideRecord('cmdb_ci');
    var query = 'sys_idIN' + sourceCMBD;
    sourceName.addEncodedQuery(query);
    sourceName.query();
    while (sourceName.next()) {
        source_nameArr.push(sourceName.name.toString());
    }
}

use source_nameArr.join(',') in the payload

View solution in original post

6 REPLIES 6

Hi Brad,

Here the issue i am facing is per below screenshot.'

 

AnandKumar1_1-1695383454357.png

 

In my logs i am getting values for source(CMDB) for the 1st row (only 2 sys_id is getting in the logs).. And the 2nd row values also i need it in the same payload to be coordinated. 

 

AnandKumar1
Tera Expert

thank you both guys, it got worked now.