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 12:34 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 12:37 PM
Let me look into it
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 12:39 PM
can you change the below line
user.query('sys_id', ids[i]);
with
user.addQuery('sys_id',ids[i]);
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 12:47 PM
same error message
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 01:42 PM
Hi Mairvette,
Sorry for my above responses. Here is the final script with testes results.
You need to create a script include and then you can call it in your client script and it will work properly. Keep the client callable check box true in your script include
// Client script
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'); // to get the comma separated ids.
var ga = new GlideAjax('UserEmails');
ga.addParam('sysparm_name', 'getEmails');
ga.addParam('sysparm_user', ids);
ga.getXML(setEmail);
function setEmail(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var clearvalue; // Stays Undefined
if (answer) {
var returneddata = answer;
g_form.setValue("email_address_add", returneddata);
} else {
g_form.setValue("email_address_add", '');
}
}
Below is your script include code
var UserEmails = Class.create();
UserEmails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEmails: function () {
var user;
var emailids='';
var userId = this.getParameter('sysparm_user').toString().split(',');
for (var i=0; i<userId.length;i++)
{
user = new GlideRecord('sys_user');
user.addQuery('sys_id',userId[i]);
user.query();
if(user.next())
{
if(emailids=='')
{
emailids=user.email;
}
else
emailids=emailids+','+user.email;
}
}
return emailids;
},
type: 'UserEmails'
});
Below are the screenshots for working code
Thanks,
Mohit Kaushik
Mohit Kaushik
ServiceNow MVP (2023-2025)