- 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-29-2024 06:41 AM
The two code examples I provided run on the server - in a workflow Approval - user activity or a Run Script activity as noted. Running an onChange Catalog Client Script that applies to the MRVS will give you incomplete results. You could do this as an onSubmit Catalog Client Script that applies to the Catalog Item, starting with your Trial 1 code, then looping through it to extract the user sys_ids from each row, but since you're doing something that doesn't need to be seen on the request form, it's best to do this with a script that runs on the server, after the request is submitted.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2024 11:51 AM
Hi Brad,
I've tried two different onSubmit scripts but still no luck. See the scripts below and please let me know if I'm missing anything. PS: Our catalog items run on a single flow that's why I've not tried the two workflow-based scripts you graciously provided.
Script 1
- 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
04-01-2024 08:27 AM
Hello Brad, Thank you for your invaluable assistance with the script. Your expertise, guidance, and patience have been instrumental in solving the challenges I faced. Thanks to your support, I was able to overcome obstacles and improve the quality of my project.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 10:11 AM
Great to hear. You are very welcome!