- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2019 12:29 PM
My use case is that I need to route approvals of a requested item based on variables within a multi row variable set (MRVS).
So far I have it working without issue by using the "startsWith" function on records that have a single MRVS row, using the code below.
answer = ifScript();
function ifScript() {
var mrvs;
var itemID = current.sys_id;
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(itemID)) {
mrvs = ritmGR.variables.po_line_items;
}
var rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++) {
var row = mrvs.getRow(i);
var category = row.po_line_item_category;
// Determine if category begins with 150
var result = category.startsWith("150");
gs.print(result);
if (result == true) {
return 'yes';
}
return 'no';
}
}
However, this doesn't work with multiple lines/rows in the MRVS. Instead it appears to query the first row and stop.
Is there a way to instead query the entire MRVS array for a string, so that it returns TRUE if the string is found on any row and FALSE if the string is not found any any row?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2019 01:41 PM
Hi,
Replace the below lines of code like this from he if statement:
if (ritmGR.get(itemID)) {
mrvs = JSON.parse(ritmGR.variables.po_line_items);
for (var i = 0; i < mrvs.length; i++) {
var category = mrvs[i].individual_variable_name;
//......................now then if category is some thing
//.....................do something
}
}
Hope this helps.
Mark helpful or correct based on impact.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2019 12:39 PM
Is there a reason why you are calling gliderecord, and having it get the current record? Current in that context should be the very record you are getting, assuming this is in an if activity within a workflow.
Also, it returns immediately after the first loop and stops. If you want it to check all rows, you need to return outside of the loop.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-02-2019 01:41 PM
Hi,
Replace the below lines of code like this from he if statement:
if (ritmGR.get(itemID)) {
mrvs = JSON.parse(ritmGR.variables.po_line_items);
for (var i = 0; i < mrvs.length; i++) {
var category = mrvs[i].individual_variable_name;
//......................now then if category is some thing
//.....................do something
}
}
Hope this helps.
Mark helpful or correct based on impact.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2019 08:32 AM
Thanks Narendra! I got this working with a modified version of what you suggested.
Instead of looping through the lines I parsed the JSON, then joined the relevant columns into a string, then searched within that string for the value I needed to filter on.
var mrvs;
var itemID = current.sys_id;
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(itemID)) {
mrvs = JSON.parse(ritmGR.variables.po_line_items);
}
// Join array results to form a string
var mrvsString = mrvs.map(function(mrvs){
return mrvs.po_line_item_category;
}).join(",");
gs.print(mrvsString);
// Search string for CapEx category (150xxx)
if(mrvsString.indexOf("150")>-1){
gs.print("Found it!");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2019 12:10 PM
Glad that it helped you.
Cheers!