Unable to populate multiple email id's in the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 11:15 AM
Can help me @Vasantharajan N @Ankur Bawiskar
As I want to populate selected users email id's in the field.
As off now in one of the field it's getting populated by the selected users as mentioned in below
To get the details I had written mentioned Script Include
For Selected Users:
var CoUtils = Class.create();
CoUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isPublic: function() {
return true;
},
getSelectedUsers: function() {
var userDetails = [];
var userGr = new GlideRecord('sys_user');
userGr.addEncodedQuery('sys_idIN' + this.getParameter('sysparm_selected_users'));
userGr.query();
while (userGr.next()) {
userDetails.push(userGr.u_display_name + ' - ' + userGr.email);
////This line is causing the issue as if I remove + ' - ' + userGr.email it is not capturing another selected user
}
return userDetails.join('\n');
},
assignToMe : function(){
var selectedSysIds = this.getParameter('sysparm_selected_sys_ids');
var taskGr = new GlideRecord('task');
taskGr.addQuery('sys_id','IN',selectedSysIds);
taskGr.query();
while(taskGr.next()){
taskGr.assigned_to = gs.getUserID();
taskGr.update();
}
},
type: 'CoUtils'
});
For Selected User Email ID's:
var CoEmails = Class.create();
CotEmails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isPublic: function() {
return true;
},
getSelectedEmails: function() {
var userDetailsEmail = [];
var userEm = new GlideRecord('sys_user');
userEm.addEncodedQuery('sys_idIN' + this.getParameter('sysparm_selected_emails'));
userEm.query();
while (userEm.next()) {
userDetailsEmail.push(userEm.email);
//This line is causing the issue as userGr.email it is not capturing another selected user email id
}
return userDetailsEmail.join('\n');
},
assignToMe : function(){
var selectedSysEmails = this.getParameter('sysparm_selected_sys_emails');
var taskGr = new GlideRecord('task');
taskGr.addQuery('sys_id','IN',selectedSysEmails);
taskGr.query();
while(taskGr.next()){
taskGr.assigned_to = gs.getSelectedEmails();
taskGr.update();
}
},
type: 'CoEmails'
});
And I had used this Script Includes in Catalog OnChange Client Scripts
For Selected Users Catalog Client Scripts:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.clearValue('email_distribution_list_users_selected');
} else {
var ga = new GlideAjax('global.CoUtils');
ga.addParam('sysparm_name', 'getSelectedUsers');
ga.addParam('sysparm_selected_users', newValue);
ga.getXMLAnswer(function(answer) {
g_form.setValue('email_distribution_list_users_selected', answer);
});
}
}
For Selected Users Email ID's Catalog Client Scripts:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.clearValue('selected_users_email_id_s');
} else {
var ga = new GlideAjax('global.CoEmails');
ga.addParam('sysparm_name', 'getSelectedEmails');
ga.addParam('sysparm_selected_emails', newValue);
ga.getXMLAnswer(function(answer) {
g_form.setValue('selected_users_email_id_s', answer);
});
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 09:43 PM
what debugging have you done so far?
update line as this
userDetailsEmail.push(userEm.email.toString());
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 10:44 PM
@priyaj - Please update the below code to use toString() in CoEmails script include and check.
From
userDetailsEmail.push(userEm.email);
To
userDetailsEmail.push(userEm.email.toString());
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 12:17 AM
How about
For Selected Users:
while (userGr.next()) {
userDetails.push(userGr.u_display_name + ' - ' + userGr.email);
////This line is causing the issue as if I remove + ' - ' + userGr.email it is not capturing another selected user
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2024 12:37 AM
Please try below line,
userDetailsEmail.push(userEm.email + '')