Iterate multiple email id's in widgets HTML

Ankita9793
Tera Contributor

Hi all,

How can i add 2 spaces between these 2 email_id. I tried the replace method but it didn't work.

expected outcome : ahmed.moh@gmail.co.in,  sudars.awar@gmail.co.in

 

widget_Ankita>>> ahmed.moh@gmail.co.in,sudars.awar@gmail.co.in



var delname = 'Moh Ahmed, Sudars awar';

 

var delnew = delname.split(',').map(function(item) {
    return item.trim();
});

// var del_name = delname.trim();
// var delnew = del_name.split(',');

var delarray = [];
for (var i = 0; i < delnew.length; i++) {
    var getdel = new GlideRecord('sys_user');
    getdel.addQuery('name', delnew[i]);
    getdel.query();
    if (getdel.next()) {

        delarray.push(getdel.email + '');
    }
}
var delempid = delarray;

gs.print('widget_Ankita>>> ' + delarray);
gs.print('del_name>>> ' + delnew);
3 ACCEPTED SOLUTIONS

G Ponsekar
Giga Guru

Hi @Ankita9793 ,

 

You can add two spaces between the email addresses by modifying the Array.join() method. Instead of just a comma, you will join the array elements with a comma and two spaces: ',

Here is the corrected code snippet:
 
javascript
var delname = 'Moh Ahmed, Sudars awar';
 

var delnew = delname.split(',').map(function(item) {
    return item.trim();
});

var delarray = [];for (var i = 0; i < delnew.length; i++) {
    var getdel = new GlideRecord('sys_user');
    getdel.addQuery('name', delnew[i]);
    getdel.query();
    if (getdel.next()) {

        delarray.push(getdel.email + '');
    }
}var delempid = delarray.join(',  '); // Add two spaces in the join methodgs.print('widget_Ankita>>> ' + delempid);
gs.print('del_name>>> ' + delnew);

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Thanks, GP

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@Ankita9793 

try this

gs.print('widget_Ankita>>> ' + delarray.join(', '));

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

View solution in original post

Shashank_Jain
Kilo Sage

@Ankita9793 ,

 

When you need custom formatting (like ,␣␣ with 2 spaces), you should join the array manually instead of relying on the default array-to-string.

 

gs.print('widget_Ankita>>> ' + delarray.join(', ')); // <-- comma + 2 spaces

 

So the fix is simply to use .join(', ') instead of printing the raw array

 

Hope it helps!

 

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain

View solution in original post

3 REPLIES 3

G Ponsekar
Giga Guru

Hi @Ankita9793 ,

 

You can add two spaces between the email addresses by modifying the Array.join() method. Instead of just a comma, you will join the array elements with a comma and two spaces: ',

Here is the corrected code snippet:
 
javascript
var delname = 'Moh Ahmed, Sudars awar';
 

var delnew = delname.split(',').map(function(item) {
    return item.trim();
});

var delarray = [];for (var i = 0; i < delnew.length; i++) {
    var getdel = new GlideRecord('sys_user');
    getdel.addQuery('name', delnew[i]);
    getdel.query();
    if (getdel.next()) {

        delarray.push(getdel.email + '');
    }
}var delempid = delarray.join(',  '); // Add two spaces in the join methodgs.print('widget_Ankita>>> ' + delempid);
gs.print('del_name>>> ' + delnew);

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Thanks, GP

Ankur Bawiskar
Tera Patron
Tera Patron

@Ankita9793 

try this

gs.print('widget_Ankita>>> ' + delarray.join(', '));

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

Shashank_Jain
Kilo Sage

@Ankita9793 ,

 

When you need custom formatting (like ,␣␣ with 2 spaces), you should join the array manually instead of relying on the default array-to-string.

 

gs.print('widget_Ankita>>> ' + delarray.join(', ')); // <-- comma + 2 spaces

 

So the fix is simply to use .join(', ') instead of printing the raw array

 

Hope it helps!

 

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain