Pass a catalog variable type is reference(Users) into the To/CC field of an email notification

Yamini Consulta
Giga Contributor

I am looking to pass a catalog fvariable type is reference(Users) into the To/CC field of an email notification. Can anyone please HELP me with this!?

1 REPLY 1

shloke04
Kilo Patron

Hi @Yamini Consulta ,

You can make use of Notification email script here and use the code below:

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

    // Add your code here
    var getDetails = current.variables.YOUR_REFERENCE_VARIABLE_NAME_HERE;
    var usr = new GlideRecord('sys_user');
    usr.addQuery('sys_id', getDetails);
    usr.query();
    if (usr.next()) {
        email.addAddress('cc', usr.email.toString(), usr.name.toString());
    }

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

Note: Please make sure to check the correct table name on which your notification is on. I am assuming you are talking about Requested Item table.

 

Now call this notification email script in your notification as below which should send out the email to CC or BCC Users.

${mail_script:Your MAIL Script Name Created Above}
Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke