- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 10:05 AM
I have a multi-row variable set with internal name "appuser_mrvs". The MRVS has a reference variable "appuser_var" that pulls record from the sys_user tables. I wanted to drive approvals based on the users identified in the "appuser_var" variable, however I couldn't achieve that.
Now I would like to pass values from each of the rows entered on the "appuser_var" mrvs variable onto a catalog item list collector variable "fetched_appuser_var".
I've tried two onChange client scripts as seen below but didn't get any result.
_
_
Any guide on how to achieve expected result would be much appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 06:08 AM
You can do this with an onSubmit Catalog Client script that applies to the Catalog Item, not the MRVS. The script just needs to loop through the MRVS contents to extract the user sys_ids from one MRVS variable, and push each to an array - since a list collector's value is a comma-separated list of sys_ids.
function onSubmit() {
var fetchedAppUserVar = [];
var mrvs = g_form.getValue('appuser_mrvs');
if (mrvs.length > 2) { //native UI returns [] for empty MRVS value which causes a parsing error
var obj = JSON.parse(mrvs);
for (var i = 0; i < obj.length; i++) {
fetchedAppUserVar.push(obj[i].appuser_var.toString());
}
}
g_form.setValue('fetched_appuser_var', fetchedAppUserVar.join(','));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 12:07 PM
Using the MRVS internal name is the right approach. It's going to be easier to do this on a server-side script, like a workflow Run Script / Approval activity, or Business Rule. Do you need to see the list collector variable populated on the form before the record is submitted? You are running this script onChange of which variable? Start with getting the MRVS JSON string without parsing it to confirm the value:
var gr = g_form.getValue('appuser_mrvs');
alert(gr);
If you're getting the expected value, add back in the parse, then check the number of rows
var gr = JSON.parse(g_form.getValue('appuser_mrvs'));
var numerOfRows = gr.length;
alert(numberOfRows);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 12:30 PM
Hello Brad, thanks for your guide and script provided.
Do you need to see the list collector variable populated on the form before the record is submitted? No. I intend to have the list collector variable hidden on the catalog item view and read-only on RITM & SCTask.
You are running this script onChange of which variable? I ran the onChange script on the the MRVS reference variable "appuser_var" inside the MRVS but that failed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 12:49 PM
If you run this script inside the MRVS you would need to use g_service_catalog.parent.getValue('appuser_mrvs'), to access the MRVS variable on the parent form, but that will retrieve the contents of the MRVS before the current row is added. This is a lot simpler since you don't need/want to see it on the form. If you are using a (legacy) workflow, the Approval - user script would look like this:
answer = [];
var mrvs = current.variables.appuser_var;
var rowCount = mrvs.getRowCount();
for (var i=0; i<rowCount; i++) {
var row = mrvs.getRow(i);
answer.push(row.appuser_var.toString());
}
Or the Run Script to populate the list collector variable with the users from the MRVS would look like this:
var lc = [];
var mrvs = current.variables.appuser_var;
var rowCount = mrvs.getRowCount();
for (var i=0; i<rowCount; i++) {
var row = mrvs.getRow(i);
lc.push(row.appuser_var.toString());
}
current.variables.fetched_appuser_var = lc.join(',');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 03:10 PM
Hi Brad - thank you for your continued help on this. I've tried the run script but getting error. I've included a screenshot.