Add the 'requested_for' variable as a CC to the Approval Request notification

rachelconstanti
Mega Sage

I have been tasked with adding the 'requested_for' variable as a CC to the approval request notification.  This notification uses email template 'change.itil.approve.role'.

I have created an email script 'cc_requested_for' with this code:

 
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {

// Add your code here
current.tableName() == 'sc_req_item';
email.addAddress("cc", current.getValue('requested_for'), current.getValue('name'));

})(current, template, email, email_action, event);

 

This has been added to the email template 'change.itil.approve.role' however the requested for is not being added to the email notification.

 

How do I fix this?

Thank you,

Rachel

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@rachelconstanti 

do this if you are talking about requested_for variable and not field on RITM

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    // Add your code here
    if (current.source_table == 'sc_req_item') {
        var gr = new GlideRecord("sc_req_item");
        gr.addQuery("sys_id", current.sysapproval);
        gr.query();
        if (gr.next()) {
            email.addAddress("cc", gr.variables.requested_for.email.toString(), gr.variables.requested_for.name.toString());
        }
    }

})(current, template, email, email_action, event);

if you are talking about requested_for field on RITM then use this

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    // Add your code here
    if (current.source_table == 'sc_req_item') {
        var gr = new GlideRecord("sc_req_item");
        gr.addQuery("sys_id", current.sysapproval);
        gr.query();
        if (gr.next()) {
            email.addAddress("cc", gr.requested_for.email.toString(), gr.requested_for.name.toString());
        }
    }

})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

@Ankur Bawiskar 

Thank you so very much for your suggestion.  I used the script for 'requested_for' variable.  Test emails added the requested_for variable as a CC on the email.

@Ankur Bawiskar - thank you again for your suggestion as that worked however one caveat - if there are multiple approvers the requested_for is CC'd on each email.  Is there a way to script this so that they only receive one copy of the email if there are multiple approvers?

@rachelconstanti 

You can't control it such that it sends only 1 email for all the approval records

since there will be multiple approval records, email will be sent for each and for each email CC will be included.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader