Multiple Values in Text Field

kutvaram
Tera Expert

Hi All,

I have a list collector field in the catalog item which will fill in multiple comma separated values.

I need to get those multiple values in a single line text box.

How to achieve it? Here is my code:

var test=newValue.split(',');

                                                                                             

                                              for(i=0;i<test.length;i++)

                                                                     

                                              {

                                                                      var ShareUsers = new GlideRecord('sys_user');

                                                                      ShareUsers.addQuery('sys_id',test[i]);

                                                                      ShareUsers.query();

                                                                      if(ShareUsers.next()){

                                                                                            g_form.setValue('share_display_text', ShareUsers.email + ",");

             

                                                                      }

                                              }

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Ramdoss,



here is the updated script:


I have taken an array and stored the emails in that and then after for loop populated it



var test=newValue.split(',');


var emailArray = [];



for(i=0;i<test.length;i++)    


{


var ShareUsers = new GlideRecord('sys_user');


ShareUsers.addQuery('sys_id',test[i]);


ShareUsers.query();


if(ShareUsers.next()){


emailArray.push(ShareUsers.email.toString);


}


}


g_form.setValue('share_display_text', emailArray);



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Ramdoss,



here is the updated script:


I have taken an array and stored the emails in that and then after for loop populated it



var test=newValue.split(',');


var emailArray = [];



for(i=0;i<test.length;i++)    


{


var ShareUsers = new GlideRecord('sys_user');


ShareUsers.addQuery('sys_id',test[i]);


ShareUsers.query();


if(ShareUsers.next()){


emailArray.push(ShareUsers.email.toString);


}


}


g_form.setValue('share_display_text', emailArray);



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


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

Gurpreet07
Mega Sage

Hi Ram,



It would be great if you use GlideAjax for this. It involves a while loop and GlideRecord will impact performance a lot.



Code in script include:


var newValue = this.getParameter(newValue);


var strEmails = ''


                                                                  var ShareUsers = new GlideRecord('sys_user');


                                                                      ShareUsers.addQuery('sys_id','IN',newValue);


                                                                      ShareUsers.query();


                                                                    while(ShareUsers.next()){


                                                                                      strEmails += ','+ShareUsers.email;


                                                                                  }


strEmails = strEmail.substring(1);


return strEmails;




Client Script


Call above script include and pass parameter newValue .   set return value using g_form.setValue


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Ramdoss,



Thanks for marking the answer as correct. Could you also mark it as helpful and hit like. Thanks in advance.



Regards


Ankur


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