- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 11:50 AM
What changes to the code should I do to achieve the desired output?
We have a workflow with a Run Script step that has the following script:
var groups = current.variables.groups_mrvs;
var groupStr = JSON.stringify(groups);
However, groupStr returns the following data:
[ {
"group" : "TeamA",
"group_permissions" : "f392c4e71bd54d1021adfeeccd4bcbe6,0bd248e71bd54d1021adfeeccd4bcbe1"
} ]
The desired output should be:
[{"TeamA":["Create","Update"]
}]
Groups (Select Box) and Group Permissions (List Collector) are part of the groups_mrvs which is a multi-row variable set.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 02:48 PM
Your desired output looks a little misleading in that you're taking the value of 2 variables, but presenting it in a name : value format. In any case, if that's what you want, you'll need to build it yourself from the MRVS JSON (your groups script variable). You'll also need to do a GlideRecord on the list collector referenced table to get the display value associated with each sys_id, so something like this will get you closer:
var groupArr = [];
var groupPermArr = [];
var groups = current.variables.groups_mrvs; //creates an array of each row of variable names and values stored in the Multi Row Variable Set
var rowCount = mrvs.getRowCount();
for (var i=0; i<rowCount; i++) { //for each row in the MRVS
groupPermArr = [];
var row = mrvs.getRow(i);
var groupPerm = new GlideRecord('dms_document_group_permission'); //list collector reference table
groupPerm.addQuery('sys_id', 'IN', row.group_permissions.toString());
groupPerm.query();
while (groupPerm.next()) {
groupPermArr.push(groupPerm.type); //display field on list collector table
}
groupArr.push({
row.group.toString() : groupPermArr.join(',')
});
}
var groupStr = JSON.stringify(groupArr.join(','));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2022 02:48 PM
Your desired output looks a little misleading in that you're taking the value of 2 variables, but presenting it in a name : value format. In any case, if that's what you want, you'll need to build it yourself from the MRVS JSON (your groups script variable). You'll also need to do a GlideRecord on the list collector referenced table to get the display value associated with each sys_id, so something like this will get you closer:
var groupArr = [];
var groupPermArr = [];
var groups = current.variables.groups_mrvs; //creates an array of each row of variable names and values stored in the Multi Row Variable Set
var rowCount = mrvs.getRowCount();
for (var i=0; i<rowCount; i++) { //for each row in the MRVS
groupPermArr = [];
var row = mrvs.getRow(i);
var groupPerm = new GlideRecord('dms_document_group_permission'); //list collector reference table
groupPerm.addQuery('sys_id', 'IN', row.group_permissions.toString());
groupPerm.query();
while (groupPerm.next()) {
groupPermArr.push(groupPerm.type); //display field on list collector table
}
groupArr.push({
row.group.toString() : groupPermArr.join(',')
});
}
var groupStr = JSON.stringify(groupArr.join(','));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 03:10 PM
Thanks. I actually went with a similar solution. I was thinking that there might be an easier way especially with list collectors in an MRVS returning sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 04:02 AM
Hi, I had the similar problem, and I couldn't find a solution. Things like looping Object.keys(mrvs); dodn't work as those keys are internal functions, and so on.
In the end, the solution is laughably easy.
var mrvsJSON = JSON.parse(current.variables.mrvs+"");
Works like charm.
Hope this helps someone later as well 🙂