
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2020 08:49 AM
Hi
I have a string variable where users enter names by comma separating( field name - colleagues1) and i have another variable which will store the email address of those names by comma separated.
I wrote a catalog client script and script include for this. It worked fine when the variable (colleagues1) where users are selected is a list collector but if the variable is a string, it isnt going in the loop and always just returning email address of 1st user selected.
Please find the script include -
I checked, the values are coming correctly from client script and the for loop is also running fine.
Works first time, but subsequently, it isn't going to else condition
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2020 04:47 AM
Hi,
might be some space in the name
please try this and trim the value
gr.addQuery('name', count[i].trim());
Also did you check those users are having the email with @ whatever your query is
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2020 09:03 AM
Hi,
please update script as below
getEmailSharePoint: function(){
var userName = this.getParameter('sysparm_s');
var arr = userName.toString().split(',');
var arr1 = [];
var userRec = new GlideRecord('sys_user');
userRec.addActiveQuery();
userRec.addQuery('email', 'IN', arr);
userRec.query();
while(userRec.next()){
arr1.push(userRec.email.toString());
}
return arr1.toString();
},
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2020 12:59 AM
Its giving blank value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2020 01:49 AM
Hi,
Did you check the query is getting satisfied or not
please share your complete script for reference
Try adding logs
getEmailSharePoint: function(){
var userName = this.getParameter('sysparm_s');
var arr = userName.toString().split(',');
var arr1 = [];
var userRec = new GlideRecord('sys_user');
userRec.addActiveQuery();
userRec.addQuery('email', 'IN', arr);
userRec.query();
gs.info('Row Count is' + userRec.getRowCount());
while(userRec.next()){
arr1.push(userRec.email.toString());
}
gs.info('Array of email is' + arr1.toString());
return arr1.toString();
},
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2020 02:15 AM
Hi.
I checked the row count is 0. Please find the script -
var FetchEmailSharePoint = Class.create();
FetchEmailSharePoint.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEmailSharePoint: function() {
var gp = ' ';
var ar = [];
var userName = this.getParameter('sysparm_s');
var count = userName.toString().split(',');
// for (var i = 0; i < count.length; i++) {
var gr = new GlideRecord('sys_user');
gr.addActiveQuery();
gr.addQuery('name', 'IN', count);
gr.addQuery('email', 'CONTAINS', '@companyemail'); //the email ids should contain a //specific text
gr.query();
gs.log("row count " + gr.getRowCount());
while (gr.next()) {
//ar.push(gr.email);
/* if (i == 0) {
gp = gr.email;
}
else{
gs.log("else condn "+gp);
gp = gp + ',' + gr.email;
}*/
ar.push(gr.email.toString());
}
// gs.log("finish array "+ar.join(','));
// return gp;
gs.log("return value " + ar.toString());
return ar.toString();
},
type: 'FetchEmailSharePoint'
});
One thing, the value coming from client script (sysparm_s) contains names of users by comma separated.