Access multi row variables outside variable set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2025 03:12 AM
Hi,
I have a ask where i need to display names of asset tagged to user, whenever any user is selected.
1. User field is of type list collector. So multiple users can be selected in one request.
2. On select of users I need to display the tagged asset. (Field type of this asset can be decided based on feasibility).
**Work around that i was trying is to use a MVRS (multi row variable set) and populate asset names whenever user is selected in list. In this variable set i have created 2 variables (User, Asset) of single line text field type. I am expected whenever user is selected in list collector, That user and associated asset is populated in this MRVS.
But the challenge is list type field is outside MRVS.
Is this feasible ? Or any other workaround to achieve this (I just want the user selected in list and associated asset is displayed on form)?
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2025 04:20 AM
Since you can select multiple users, if you need to see which user each asset is assigned to then a MRVS seems like a good approach. You can create an onChange Catalog Client Script that applies to the Catalog Item when the list collector variable changes. This script should basically wipe out and re-create the MRVS each time it runs since users in the List Collector variable can also be de-selected. Your script would look something like this
var usersArr = newValue.split(',');
var mrvs = [];
for (var i=0; i<usersArr.length; i++) {
<<GA call to SI to return list of assets for this user>>
<<in callback function...>>
mrvs.push({
"v_user_mrvs": usersArr[i],
"v_asset_mrvs": <<asset sys_id returned from GA>>
});
}
g_form.setValue('assets_mrvs', JSON.stringify(mrvs));
where v_user_mrvs is the name of the user variable in the MRVS, v_asset_mrvs is the name of the asset variable in the MRVS, and assets_mrvs is the internal name of the MRVS.
If you're not familiar, here's an excellent guide on GlideAjax which includes returning mulitple fields per result
Give the scripts a shot and post them using the insert code </> icon if you get stuck.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2025 06:19 AM
Hello @Brad Bowman ,
Thanks for you response. I did try this but i am getting undefined in the array.
I tried to check the value returned from script include. It us coming as expected but on setting it in arrray it's undefined.
for (var i = 0; i < usersArr.length; i++) {
var mrvs = {};
var gaAsset = new GlideAjax('TestUtil');
gaAsset.addParam('sysparm_name', 'getEmail');
gaAsset.addParam('sysparm_userid', usersArr[i]);
gaAsset.getXMLAnswer(parseAnswer);
function parseAnswer(response) {
var answer = response;
alert(answer); //expected value
if (answer) {
mrvs.push({
"tagged_asset": answer,
"selected_user":usersArr[i];
});
}
}
alert('hi' + mrvs[0]);//undefined
g_form.setValue('assets', JSON.stringify(mrvs));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2025 06:28 AM
update as this
Ensure your script include returns Name of user and Name of asset and not sysIds for those.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var usersArr = g_form.getValue('listCollectorVariableName').split(',');
var arr = [];
for (var i = 0; i < usersArr.length; i++) {
var mrvs = {};
var gaAsset = new GlideAjax('TestUtil');
gaAsset.addParam('sysparm_name', 'getEmail');
gaAsset.addParam('sysparm_userid', usersArr[i]);
gaAsset.getXMLAnswer(parseAnswer);
function parseAnswer(response) {
var answer = response;
alert(answer); //expected value
if (answer) {
mrvs.push({
"tagged_asset": answer,
"selected_user": usersArr[i]
});
arr.push(mrvs);
}
}
}
g_form.setValue('assets', JSON.stringify(arr));
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2025 08:29 AM
Hi @Ankur Bawiskar ,
Thanks for the response. I did try the updated logic but it is still not mapping into MRVS on the form.