We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Make Case watchlist into email CC using Email script. how we can approach?

MUDIGOLAM BHANU
Tera Contributor

I want to make cc watchlist into email CC. How we can achieve using email script?

8 REPLIES 8

Ankur Bawiskar
Tera Patron

@MUDIGOLAM BHANU 

so you want to include watch list users in CC

something like this, but please enhance

(function refineEmail(current, recipient, email, emailAction, sysEvent) {
    if (!current.watch_list.nil()) {
        var watcherIds = current.watch_list.split(',');
        for (var i = 0; i < watcherIds.length; i++) {
            var user = new GlideRecord("sys_user");
            user.addQuery("sys_id", watcherIds[i]);
            user.addQuery("notification", '2'); // Only users with enabled notifications
            user.addNotNullQuery("email"); // Must have an email address
            user.query();
            if (user.next()) {
                email.addAddress("cc", user.email, user.name);
            }
        }
    }
})(current, recipient, email, emailAction, sysEvent);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

Thanks for the solution, i tried above given it's not working.

user.addQuery("notification", '2');

above line of code,it means it will take 2 users from watchlist or how it is ? 

 

Shall we mention 2 different CC email script of different logics on one email notification body? let me know

 

Thanks,

BhanuPrakash.

 

@MUDIGOLAM BHANU 

nope

It means whichever user has notification preference enabled then only add that in CC email.

1 email script in your email notification is enough

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

If required we can use multiple- email scripts we can kept into single notification right? if not please let me know.