How I can split string values in mail script

PabloEugenG
Tera Contributor

Hello community,

 

I created a mail script to pull to the notification the first name of the assignment group members, but I receive all the names like a whole string, I would like to separate each name with a comma.

 

This is my script:

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',current.assignment_group);
gr.query();
while(gr.next())
{
gs.print(gr.user.getDisplayValue('user'));
template.print(gr.user.name.split(','));

}

 

And this is how it looks:

PabloEugenG_0-1716881272343.png

Any clue about how to fix this? Kind regards

 

1 ACCEPTED SOLUTION

Gustav Aldenbra
Kilo Sage

Hi @PabloEugenG 

You could add each name to an array and then join the array with a comma followed by a space. try this:

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', current.assignment_group);
gr.query();

var names = [];
while(gr.next()) {
    names.push(gr.user.first_name);
}

// Join the names with a comma and a space
var namesString = names.join(', ');

template.print(namesString);

 

View solution in original post

1 REPLY 1

Gustav Aldenbra
Kilo Sage

Hi @PabloEugenG 

You could add each name to an array and then join the array with a comma followed by a space. try this:

var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', current.assignment_group);
gr.query();

var names = [];
while(gr.next()) {
    names.push(gr.user.first_name);
}

// Join the names with a comma and a space
var namesString = names.join(', ');

template.print(namesString);