Email script to get all approver name and email

wai
Kilo Contributor

Hi All,

I am trying to create an notification email when there are new comments added during the approval process. I can make the email send to send event creator and the approver. However we have multiple approver and would like the email notify all of them. Would like to know how would I do it?

I am trying to use the email script and include it in the email but it never works. Would an expert review anything goes wrong?

Thanks,

Wai

*****************************************************************************************************

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

// Add your code here

var friends = new GlideRecord('sysapproval_approver');

friends.addQuery('sysapproval', current.sysapproval);

friends.query();

while(friends.next()) {

if (friends.approver.toString() != current.approver.toString()) {

addAddress("CC",friends.approver.email, friends.approver.toString());

}

}

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

*****************************************************************************************************

1 ACCEPTED SOLUTION

amaradiswamy
Kilo Sage

Hi Wai,



You have to add email.addAddress() instead of just addAddress()


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



// Add your code here


var friends = new GlideRecord('sysapproval_approver');


friends.addQuery('sysapproval', current.sysapproval);


friends.query();


while(friends.next()) {


if (friends.approver.toString() != current.approver.toString()) {


email.addAddress("CC",friends.approver.email, friends.approver.toString());


}


}



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



Regards


Swamy


View solution in original post

4 REPLIES 4

jagann
Kilo Explorer

addAddress("CC",friends.approver.email, friends.approver.toString()); email object is missing here



try   email.addAddress("CC",friends.approver.email, friends.approver.toString());







amaradiswamy
Kilo Sage

Hi Wai,



You have to add email.addAddress() instead of just addAddress()


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



// Add your code here


var friends = new GlideRecord('sysapproval_approver');


friends.addQuery('sysapproval', current.sysapproval);


friends.query();


while(friends.next()) {


if (friends.approver.toString() != current.approver.toString()) {


email.addAddress("CC",friends.approver.email, friends.approver.toString());


}


}



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



Regards


Swamy


wai
Kilo Contributor

Hi Swamy,



Thanks for your reply. You point out the main point. Now my code like below and it works!



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



// Add your code here


var friends = new GlideRecord('sysapproval_approver');


friends.addQuery('sysapproval', current.sysapproval);


friends.query();


while(friends.next()) {


if (friends.approver.toString() != current.approver.toString()) {


email.addAddress("cc",friends.approver.email, friends.approver.name);


}


template.print('TEST END');


}



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


Community Alums
Not applicable

not working