- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
HI all ,
For the single user it is goving correct answer but for the multiple users it is giving undefined answer
Can anyone correct this script :
source.u_owner_name:- multiple user id is coming ,
return: undefined output is coming
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Source: u_owner_name
Target: List Collector (sys_user)
Input format: user1,user2,user3
answer = (function transformEntry(source) {
if (!source.u_owner_name)
return '';
var owners = source.u_owner_name;
var userIds = [];
var arr = owners.split(',');
for (var i = 0; i < arr.length; i++) {
var userVal = (arr[i] || '').trim();
if (!userVal)
continue;
var userGR = new GlideRecord('sys_user');
userGR.addQuery('user_name', userVal); // change if using email or name
userGR.query();
if (userGR.next()) {
userIds.push(userGR.sys_id.toString());
}
}
// List Collector expects comma-separated sys_ids
return userIds.join(',');
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Updated Script
This version:
Handles single or multiple users
Returns comma-separated sys_ids
Returns after all users are processed
answer = (function transformEntry(source) {
if (!source.u_owner_name)
return '';
var owners = source.u_owner_name;
var userIds = [];
var arr = owners.split(',');
gs.log('TM Owners tokens=' + arr.length);
for (var i = 0; i < arr.length; i++) {
var userVal = (arr[i] || '').trim();
if (!userVal)
continue;
var userGR = new GlideRecord('sys_user');
userGR.addQuery('user_name', userVal);
userGR.query();
if (userGR.next()) {
userIds.push(userGR.sys_id.toString());
gs.log('Matched user: ' + userVal);
}
}
return userIds.join(',');
})(source);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Remember If your target field is a single reference field, ServiceNow will only accept one sys_id.
If it’s a List field, comma-separated sys_ids are correct.
If you tell me:
Target field type (Reference vs List)
Source value format (username, email, name)
I can tailor this exactly to your use case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
@Matthew Green2 : list collector field type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Source: u_owner_name
Target: List Collector (sys_user)
Input format: user1,user2,user3
answer = (function transformEntry(source) {
if (!source.u_owner_name)
return '';
var owners = source.u_owner_name;
var userIds = [];
var arr = owners.split(',');
for (var i = 0; i < arr.length; i++) {
var userVal = (arr[i] || '').trim();
if (!userVal)
continue;
var userGR = new GlideRecord('sys_user');
userGR.addQuery('user_name', userVal); // change if using email or name
userGR.query();
if (userGR.next()) {
userIds.push(userGR.sys_id.toString());
}
}
// List Collector expects comma-separated sys_ids
return userIds.join(',');
})(source);