How to get the value of the variable in request item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 07:42 PM
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.
Thanks in advance!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 08:13 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 10:37 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 09:39 PM - edited 05-29-2024 09:40 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 10:32 PM
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