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-25-2025 12:24 AM
update as this
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var users = g_form.getValue('listCollectorVariableName').toString();
var gaAsset = new GlideAjax('TestSI');
gaAsset.addParam('sysparm_name', 'getMachineNames');
gaAsset.addParam('sysparm_userid', users);
gaAsset.getXMLAnswer(parseAnswer);
function parseAnswer(response) {
g_form.setValue('assets', JSON.stringify(answer));
}
}
Script Include function:
getMachineNames: function() {
var userSysId = this.getParameter('sysparm_users');
var listValues = [];
var grDetails = new GlideRecord('sys_user');
grDetails.addEncodedQuery('sys_idIN' + userSysId);
grDetails.query();
while (grDetails.next()) {
listValues.push({
"Machine": grDetails.getValue('machine'),
"userId": grDetails.getValue('user_name')
});
}
return JSON.stringify(listValues);
},
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 04:37 AM
don't use MRVS here.
Let them select multiple users and have a multi line text variable
Simply use onChange catalog client script and populate the variable in this format
User A - Asset 1
User B - Asset 2
sample working script here; enhance for your case
Populate Email Addresses of users selected in List Collector variable to Multi Line Text Variable
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 06:07 AM - edited ‎06-24-2025 06:19 AM
Hi @Ankur Bawiskar ,
The issue with multi line field is that we will not be able to differentiate which asset belong to which user as the field will display all the machine names together separated by ,.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-24-2025 06:24 AM
Nope, it will look like this and it will be easy to differentiate
Abel Tuter - Dell Computer, Webcam
Beth Angelin - Asus Laptop, Printer
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-25-2025 12:25 AM
update your client script like this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var usersArr = newValue.split(',');
var gaAsset = new GlideAjax('TestSI');
gaAsset.addParam('sysparm_name', 'getMachineNames');
gaAsset.addParam('sysparm_users', newValue);
gaAsset.getXMLAnswer(parseAnswer);
function parseAnswer(response) {
var answer = JSON.parse(response);
if (answer) {
alert(answer) //comment this added for testing
g_form.setValue('machine_names', answer);
}
}
}
the issue is in the script include
you are querying the sys_user table
you are suppose to query the assets related table right?
replace the sys_user table with asset table
in which table the assets are in?
is machine and user_name are proper field names in that table?
please share the asset table name screenshot of that table would be great to include filed names and backend names of machine and user name fields too
getMachineNames: function() {
var userSysId = this.getParameter('sysparm_users');
var listValues = [];
var grDetails = new GlideRecord('sys_user');//query correct table
grDetails.addEncodedQuery('sys_idIN' + userSysId);//put proper filter
grDetails.query();
while (grDetails.next()) {
listValues.push({
"tagged_asset": grDetails.getValue('machine'), //get proper field names
"selected_user": grDetails.getValue('user_name')
});
}
return JSON.stringify(listValues);
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya