addAddress() in Email scripts

Madhan007
Tera Contributor

Hi Everyone,

I am defining an Email script to add the approver of a HR case in  cc and bcc of a notification triggered by an Event in the Flow. Please find the script below. Current object is the Approval  GlideRecord passed from the event.

var gr = new GlideRecord('sn_hr_core_case');

    if (gr.get(current.sysapproval)) {

        var approvalgr = new GlideRecord('sysapproval_approver');

        approvalgr.addQuery('sysapproval', gr.sys_id);
        approvalgr.query();
        while (approvalgr.next()) {

            if (approvalgr.approver.email) {

                var emailString = approvalgr.approver.email.toString();
                var displayName = approvalgr.approver.name;
                email.addAddress("cc", emailString, displayName);

            }
        }

 

    }

 

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

 

I logged all the details using gs.info and everything is fine,  except that cc and bcc are not being populated in Email logs.

when I run the same script through Background scripts, its throwing an error sayin that email is not defined

Please pour your Insights.

Thank you!