Add multiple email addresses to List Collector on Service Portal/Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 10:20 AM
Hello.
Within a catalog item, we have two fields. One is for the user's name the other for their email address.
I've used the table 'sys_user' for both fields. When the user's name is populated, I have it automatically adding their email address to the specific email field, both with 'List Collector' as their variable type.
Issue I am having, is if multiple users are added to the User field, no email address (even previously displayed for the first user) will be displayed. How do I get each additional email address to be displayed in the List Collector / email field?
- Labels:
-
Incident Management
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 11:51 AM
oops give it var instead of int. Sorry my mistake.
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 12:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 12:10 PM
Sorry My bad, I was not using any editor while writing the script so it is throwing errors which is not in code . But the comment,
you can use the fresh script as shown below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ids = g_form.getValue('users_add').toString().split(','); // to get the comma separated ids.
var emailids = '';
var user;
for (var i = 0; i < ids.length; i++)
{
user = new GlideRecord('sys_user');
user.query('sys_id', ids[i]);
user.query(myCallbackFunction);
}
function myCallbackFunction(user) {
if (user.next())
{
if (emailids =='')
{
emailids = user.email; // for first record
} else {
emailds = emailids + ',' + user.email; //if multiple records
}
}
}
g_form.setValue('email_address_add', emailds);
}
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 12:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 12:31 PM
can you try running this in native UI first. I want to know if this code is working or not. If yes then we can modify it for portal as well.
Please confirm
Mohit Kaushik
ServiceNow MVP (2023-2025)