- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2024 08:33 PM
The below is part of the script include that failed to return the list of users.
How can I return a list of users based on an array of email addresses?
var email = []; //this contains (abc@org.com,efg@org.com,hij@org.com)
var emailArr = email.split(',');
var userArr = [];
for (var i = 0; i < emailArr.length; i++) {
var grUser = new GlideRecord('sys_user');
grUser.addQuery('email', emailArr[i]);
grUser.query();
if (grUser.next()) {
userArr.push(grUser.getUniqueValue());
}
}
var requester = userArr.join(',');
return (requester.toString());
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2024 08:49 PM
Hi, in your script you are splitting the array email', and then trying to loop over the result,
but split() is a string method and so the result of the split is undefined.
As you already have a defined array, you can loop through its elements without having to make any changes.
Testing in PDI background script
var email = ['admin@example.com','abel.tuter@example.com', 'lucy.barnes@example.com', 'anthony.roy@servicneow.com']; //this contains (abc@org.com,efg@org.com,hij@org.com)
var emailArr = email.split(',');
gs.info('emailArr ' + typeof emailArr);
var userArr = [];
for (var i = 0; i < email.length; i++) {
var grUser = new GlideRecord('sys_user');
grUser.addQuery('email', email[i]);
grUser.query();
if (grUser.next()) {
userArr.push(grUser.getUniqueValue());
}
}
gs.info(userArr.toString());
//var requester = userArr.join(',');
//return (requester.toString());
'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2024 08:49 PM
Hi, in your script you are splitting the array email', and then trying to loop over the result,
but split() is a string method and so the result of the split is undefined.
As you already have a defined array, you can loop through its elements without having to make any changes.
Testing in PDI background script
var email = ['admin@example.com','abel.tuter@example.com', 'lucy.barnes@example.com', 'anthony.roy@servicneow.com']; //this contains (abc@org.com,efg@org.com,hij@org.com)
var emailArr = email.split(',');
gs.info('emailArr ' + typeof emailArr);
var userArr = [];
for (var i = 0; i < email.length; i++) {
var grUser = new GlideRecord('sys_user');
grUser.addQuery('email', email[i]);
grUser.query();
if (grUser.next()) {
userArr.push(grUser.getUniqueValue());
}
}
gs.info(userArr.toString());
//var requester = userArr.join(',');
//return (requester.toString());
'