Comma separated values not returning from script include to client script

Chenab Khanna
Tera Expert

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 - 

find_real_file.png

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

1 ACCEPTED SOLUTION

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

16 REPLIES 16

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Its giving blank value

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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.