Help with a mail script to add recipients for emai notification from the sysapproval_approver table

jlaue
Kilo Sage

Hello - I am working with a custom table extended from the Task table.  I have approvals configured in a workflow for this table.  When an approval record is rejected, I am trying to add several recipients from 2 User Reference fields on the custom table.  The notification is being sent OK, however my mail script doesn't appear to be working, to add recipients from the custom table to the rejection mail notification.  Was hoping someone could take a look at my script and see if I am going about it the wrong way. 

 

Here is my mail script:

 

(function runMailScript(current, template, email, email_action, event) {

 

var ecn = current.getValue('document_id');
var ecnfields = new GlideRecord("custom_table_here");
ecnfields.addQuery("sys_id", ecn);
ecnfields.query();

 

if (ecnfields.next()) {

var behalf = ecnfields.getValue('on_behalf_of');
var initiate = ecnfields.getValue('initiated_by');

 

email.addAddress("cc", behalf.email.toString(), behalf.name.toString());
email.addAddress("cc", initiate.email.toString(), initiate.name.toString());

}

 

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

 

Thank you!!

1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @jlaue 

Which should be correct is these 2 lines.

 

var behalf = ecnfields.getValue('on_behalf_of');
var initiate = ecnfields.getValue('initiated_by');

 

 

I assume these fields on_behalf_of and initiated_by are the reference fields.

So let's try the below adjustment.

 

(function runMailScript(current, template, email, email_action, event) {

    var ecn = current.getValue('document_id');
    var ecnfields = new GlideRecord("custom_table_here");
    ecnfields.addQuery("sys_id", ecn);
    ecnfields.query();

    if (ecnfields.next()) {
        email.addAddress("cc", ecnfields.on_behalf_of.email.toString(), ecnfields.on_behalf_of.name.toString());
        email.addAddress("cc", ecnfields.initiated_by.email.toString(), ecnfields.initiated_by.name.toString());
    }

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

 

 

Let me know if it works for you.

 

Cheers,

Tai Vu

View solution in original post

2 REPLIES 2

Tai Vu
Kilo Patron
Kilo Patron

Hi @jlaue 

Which should be correct is these 2 lines.

 

var behalf = ecnfields.getValue('on_behalf_of');
var initiate = ecnfields.getValue('initiated_by');

 

 

I assume these fields on_behalf_of and initiated_by are the reference fields.

So let's try the below adjustment.

 

(function runMailScript(current, template, email, email_action, event) {

    var ecn = current.getValue('document_id');
    var ecnfields = new GlideRecord("custom_table_here");
    ecnfields.addQuery("sys_id", ecn);
    ecnfields.query();

    if (ecnfields.next()) {
        email.addAddress("cc", ecnfields.on_behalf_of.email.toString(), ecnfields.on_behalf_of.name.toString());
        email.addAddress("cc", ecnfields.initiated_by.email.toString(), ecnfields.initiated_by.name.toString());
    }

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

 

 

Let me know if it works for you.

 

Cheers,

Tai Vu

jlaue
Kilo Sage

That worked, thank you so much for your help!!