Notification not triggered when Requested for and Opened by are same (RITM notification)

shaik riyaz1
Tera Contributor

Hi,

I am working on a notification on Requested Item (sc_req_item).

Requirement:
Send email notification to:

  1. Requested for (TO)

  2. Opened by (CC)

  3. 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);

3 REPLIES 3

PoonkodiS
Mega Sage

Hi @shaik riyaz1 

Usually email.addAddress  contains three values , but you mentioned only two values

PoonkodiS_0-1769442167316.png

check this syntax and give the feedback

 

Regards,

Poonkodi

KanteS
Giga Guru

Hi @shaik riyaz1 

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

 



Brian Lancaster
Kilo Patron

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.

BrianLancaster_0-1769443677396.png