Notification not triggered when Requested for and Opened by are same (RITM notification)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi,
I am working on a notification on Requested Item (sc_req_item).
Requirement:
Send email notification to:
Requested for (TO)
Opened by (CC)
Manager of Requested for (CC)
Issue
When Requested for ≠ Opened by, notification works correctly.
When Requested for = Opened by, notification was not triggering initially.
After enabling Send to event creator, notification triggers, but:
Same user appears in TO and CC
I want to avoid duplicate email addresses in CC
Email script:
(function runMailScript(current, template, email, email_action, event) {
// Add opened by
if (current.opened_by && current.opened_by.email) {
email.addAddress("cc", current.opened_by.email);
}
// Add manager of requested for
if (current.request && current.request.requested_for) {
var userGR = new GlideRecord("sys_user");
if (userGR.get(current.request.requested_for)) {
if (userGR.manager && userGR.manager.email) {
email.addAddress("cc", userGR.manager.email);
}
}
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Usually email.addAddress contains three values , but you mentioned only two values
check this syntax and give the feedback
Regards,
Poonkodi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
please try below code might work
(function runMailScript(current, template, email, email_action, event) {
var requestedFor = current.request.requested_for;
var openedBy = current.opened_by;
// Add Opened by only if different from Requested for
if (openedBy && openedBy.email && openedBy != requestedFor) {
email.addAddress("cc", openedBy.email);
}
// Add Manager of Requested for
if (requestedFor) {
var userGR = new GlideRecord("sys_user");
if (userGR.get(requestedFor) && userGR.manager && userGR.manager.email) {
email.addAddress("cc", userGR.manager.email);
}
}
})(current, template, email, email_action, event);
If this resolved your issue, please mark this response as the correct answer and give it a like
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
You are comparing two different things here. current.opened_by && current.opened_by.email. Current.opened_by will give you the record sys_id were current.opbened_by.email will return the email address from that opened_by record.
(function runMailScript(current, template, email, email_action, event) {
// Add opened by
if (current.opened_by != current.request.requested_for) {//Check to see if opened by and requested for are not the same users.
email.addAddress("cc", current.opened_by.email);
}
// Add manager of requested for
email.addAddress("cc", current.request.requested_for.manager.email;
}
}
}
})(current, template, email, email_action, event);
On another note. Do you have to have them on the CC line. If you can have them on the two line you can just do this on the who will receive tab. The system will not display the email address twice of the opened by and requested for are the same.
