Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Need a client script for comma separated

Saib1
Tera Guru

Hi Team,

 

Please find the below screenshot

 

Username has the collector which contains the value as reference from sys_user table

 

For Example:

salma@gmail.com

rekha@gmail.com

ameer@gmail.com

 

Saib1_1-1700129221930.png

 

I need to write a client script to get those 3 value in comma separated and save it in below user id field

 

Saib1_0-1700129119576.png

 

I have a client script for getting one value , Not sure how to get 3 values with comma separated

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var user = g_form.getReference('first_name', getdetails);
function getdetails(user) {
g_form.setValue('email', user.email);
g_form.setValue('user_id', user.user_name);
}
}

 

1 ACCEPTED SOLUTION

@Ankur Bawiskar 

 

as per my requirement you code this helps me ,It displays the sys id to string like below

 

rekha@gmail.com,sal@gmail.com,halit@gmail.com

 

Code

******

var newValue= "8fe3414f1bddb410f6e7a822b24bcb4b,133bd44f1bc5a910f03fa861f54bcb3a,cea8a0f71b978194880235e4464bcb70"
var userArr = newValue.toString().split(',');
var emailArr = [];
 
for(var i = 0; i < userArr.length; i++) {
var grUser = new GlideRecord('sys_user');
 
if(grUser.get(userArr[i].toString())) {
emailArr.push(grUser.getValue('email'));
}
}
 
var values = emailArr.join();
var test = values;
gs.print(values);

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@Saib1 

you cannot use getReference on list collector. it can be used only for reference variable

in your requirement you need to use GlideAjax and return the usernames from that function as comma separated value

I hope you will be able to do this using the GlideAjax syntax from docs

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar 

Hope you misunderstood my above one. Can you give me the code

I have sample below 

 

salma@gmail.com

rekha@gmail.com

ameer@gmail.com

 

Need an output to store this value like this in user id salma@gmail.com , ,rekha@gmail.com ,ameer@gmail.com

 

Is that possible 

@Saib1 

I have understood the requirement and also informed this is not possible using getReference on list collector

Please use GlideAjax

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar - i am not sure how to get from GlideAjax