- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2025 02:27 AM
Hi All,
I have a requirement to create a UI button (Send Emails) in the Requested Item table. On click of button, outlook will open.
Recipients would be- Active sctaks' assigned to and if assigned to is empty then the member of assignment group.
Here is my script, but it is setting undefined recipient.
function emailOutlook() {
var ritmNumber = current.number;
var recipients = [];
// Query for tasks related to the RITM
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', ritmNumber);
taskGR.addQuery('active', 'true');
taskGR.query();
while (taskGR.next()) {
if (taskGR.assigned_to) {
recipients.push(taskGR.assigned_to.email);
} else if (taskGR.assignment_group) {
var groupMembersGR = new GlideRecord('sys_user_grmember');
groupMembersGR.addQuery('group', taskGR.assignment_group);
groupMembersGR.query();
while (groupMembersGR.next()) {
recipients.push(groupMembersGR.user.email);
}
}
}
// Remove duplicate email addresses
recipients = Array.from(new Set(recipients));
var rec = recipients.join(',');
window.open('mailto:' + rec + '?subject=testing&bodymessage%20goes%20here', 'email');
}
Please help in this.
Thanks,
Sam
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2025 03:24 AM
please use GlideAjax and get all the recipients and then use window.open
I hope you will be able to do this.
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-03-2025 02:54 AM
I am not saying manual.
did you try to use this line and see if it works only 1 recipient?
Do you have outlook configured in your laptop to verify this?
window.open('mailto:' + 'abel.tuter@example.com' + '?subject=testing&bodymessage%20goes%20here', 'email');
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-03-2025 02:50 AM
Hi @Ankur Bawiskar ,
This is the error
Uncaught ReferenceError: current is not defined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2025 02:50 AM
I have checked the Client checkbox. Will it behave like client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2025 03:01 AM
ensure UI action is client side only
current won't work in client side
try this
function emailOutlook() {
var ritmSysId = g_form.getUniqueValue();
var recipients = [];
// Query for tasks related to the RITM
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', ritmSysId);
taskGR.addActiveQuery();
taskGR.query();
while (taskGR.next()) {
if (taskGR.assigned_to) {
recipients.push(taskGR.assigned_to.email.toString());
} else if (taskGR.assignment_group) {
var groupMembersGR = new GlideRecord('sys_user_grmember');
groupMembersGR.addQuery('group', taskGR.assignment_group);
groupMembersGR.query();
while (groupMembersGR.next()) {
recipients.push(groupMembersGR.user.email.toString());
}
}
}
alert('recipients' + recipients.toString());
// Remove duplicate email addresses
window.open('mailto:' + recipients.toString() + '?subject=testing&bodymessage%20goes%20here', 'email');
}
OR
you can use GlideAjax and get all the array and then use window.open
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-03-2025 03:21 AM - edited ‎03-03-2025 03:21 AM
Hi @Ankur Bawiskar ,
In the console it was saying error toString() is not defined.
When I removed toString().
Now alert is coming but empty and it is also redirecting to the outlook but same empty value