- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2017 06:09 AM
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 + ",");
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2017 06:24 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2017 06:24 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2017 06:29 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2017 07:02 AM
Hi Ramdoss,
Thanks for marking the answer as correct. Could you also mark it as helpful and hit like. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader