How to get the value of the variable in request item

ma kaiyue
Giga Guru

How can I get the value of the variable in the multi-row in the variable set in request item, I used

variables.<variables set name>

but there is an error like this.

makaiyue_0-1717036812262.png

 

Thanks in advance!

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@ma kaiyue 

mrvs stores info in JSON format. you need to parse it to get the value

var jsonString = current.variables.mrvsVariableSetName;

var obj = JSON.parse(jsonString);

// now get the variable value

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

 

Thanks for your reply.

What if it's not a current request item, I want to query it in the sc_req_item table and return the value of a variable in the multi-rows when it equals to a specific value, is this possible to achieve?

Regards

SN_Learn
Kilo Patron
Kilo Patron

Hi @ma kaiyue,

 

Please try the below:

 

var mrvsData = current.variables.<internal_name_of_mrvs>.toString();

var mrvsVal = JSON.parse(mrvsData);
for (var i = 0; i < mrvsVal.length; i++) {
var var1 = mrvsVal[i].<variable_name1>; //access the variable 1
var var2 = mrvsVal[i].<variable_name2>; //access the variable 2
}

 

 

If my answer helped you in any way, please mark it as helpful or correct.

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Thanks for your reply.

What if it's not a current request item, I want to query it in the sc_req_item table and return the value of a variable in the multi-rows when it equals to a specific value, is this possible to achieve?

Regards