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

@Community Alums 

 

I have the list collector and value contains below

 

salma@gmail.com

rekha@gmail.com

ameer@gmail.com

 

need to get those value on other field user_id in comma separated like  = salma@gmail.com   ,rekha@gmail.com ,ameer@gmail.com