- 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 01:59 PM
