Transform map to set multiple values in a list field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2023 03:42 AM
Hi,
I'm trying to set multiple values in a list field via a transform map. The field is referencing the sys_user table.
function setApproverV2() {
var input_array = source.u_approver.split(',');
for (var i = 0; i < input_array; i++) {
var getUser = new GlideRecord('sys_user');
getUser.addActiveQuery();
getUser.addQuery('user_name', input_array[i]);
getUser.query();
while (getUser.next()) {
target.u_approver = getUser.sys_id;
}
}
}
The outcome I'm trying to achieve with the script is to loop through the list from the source file, separate the values in the Approver column, find the user records in the sys_user table and then set target value with sys_id of the users.
Anyone see where i'm going wrong?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2023 03:47 AM
Hi @Steven Watts2,
You are always setting it to the one value in the while loop.
Try this:
function setApproverV2() {
var input_array = source.u_approver.split(',');
var approvers = [];
for (var i = 0; i < input_array; i++) {
var getUser = new GlideRecord('sys_user');
getUser.addActiveQuery();
getUser.addQuery('user_name', input_array[i]);
getUser.query();
if (getUser.next()) {
approvers.push(getUser.getUniqueValue());
}
}
target.u_approver = approvers.toString();
}
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2023 05:14 AM
Hi Peter,
Thanks for the assistance. I've just tried this and unfortunately when the records are created no value is being populated in the Approver list field. I'll add some logging statements to check the values being stored in 'approvers'.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2023 05:47 AM
Hi @Steven Watts2,
Let me know if you need anymore help. If so, please add a excert from your import data, in order to help you better.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2023 06:15 AM
try script shared by Peter once and share the update
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader