Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

email script to add delegate of approver user in cc

Rajavardhini
Tera Contributor

Hi All,

 

I have used below email script to add delegate of approver user in cc of notification but the script is not working.

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,

    /* Optional EmailOutbound */

    email, /* Optional GlideRecord */ email_action,

    /* Optional GlideRecord */

    event) {

 

    // Add your code here

    var delegate = new GlideRecord('sys_user_delegate');

 

    delegate.addQuery('user', current.approver.sys_id);

 

    delegate.addQuery('starts', '<=', gs.nowNoTZ());

 

    delegate.addQuery('ends', '>=', gs.nowNoTZ());

 

    delegate.addQuery('approvals', 'true');

 

    delegate.query();

 

    while (delegate.next()) {

 

        // get the email address of the delegate if they have notification enabled

 

        var usr = new GlideRecord('sys_user');

 

        usr.addQuery('sys_id', delegate.delegate);

 

        usr.addQuery('notification', '2');

 

        usr.addQuery('active', 'true');

 

        usr.query();

 

        while (usr.next()) {

 

            // add the delegate's email to the "cc" list

 

            email.addAddress("cc", usr.email, usr.name);

 

        }

 

    }

 

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

 

Could you please check if there any mistakes in my script.

 

1 REPLY 1

Runjay Patel
Giga Sage

Hi @Rajavardhini ,

 

I check the code, its working.

You can check the below.

1. Delegate user has notification enabled and active true.

2. Delegate start and end date falls under.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

 

Part 2. In this video i have talked about overview on ServiceNow platform/tool. How you can opt for personal dev instance (PDI)? how to login in ServiceNow instance and navigation to OOB modules. For document please visit: https://servicenowwithrunjay.com/ Follow Facebook page for latest update on