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

Hi,

are those values the name field of sys_user then the script shared by me should work fine

Regards
Ankur

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

Hi. I am getting blank - 

find_real_file.png

Email ids for add members field should give email ids of those 3 names.

Also, row count returned 0

Hi,

are you using the script I shared or the one which you posted in the question

if you are using script I shared please share complete client script and script include function

Regards
Ankur

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

I used the one you shared. 

find_real_file.png

 

Hi,

since you informed the row count is 0 so it means the query is not happening

the variable colleagues1 is string type and holds the name so you should query with the name field

Did you check exact name is present in the sys_user table

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('name', 'IN', arr); // see change here

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