Only ITIL User should able to receive a CATALOG TASK email notification

Jeck Manalo
Tera Guru

Hello Everyone,

 

I am trying to do some scripting in the email notification advance view. 

 

Where I want to achieve that only a ITIL member has able to receive the email when the catalog task is assigned to there group.


e.g the group is combination of IT people and HR. so what i want here is that only IT people can able to receive that notification.

 

Anyone knows how to achieve this ?

 

Here is the settings:

When to send:

Send when: record inserted or updated

Condition: assignment group changes or actual start changes and assigned to is empty

 

Who will receive:

Users/Group in field: assignment_group

Send to event creator: True

 

I added this code in advance view but non-itil member can still able to receive the email.

 

(function process(/* GlideRecord */ current, /* TemplatePrinter */ template, /* EmailOutbound */ email, /* EmailTemplate */ email_template, /* GlideRecord */ event) {
    var recipients = [];
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('group', current.assignment_group);
    gr.query();
    while (gr.next()) {
        var user = new GlideRecord('sys_user');
        user.get(gr.user);
        if (user.hasRole('itil')) {
            recipients.push(user.email);
        }
    }
    email.setRecipients(recipients.join(','));
})(current, template, email, email_template, event);
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Jeck Manalo 

within email script you can't set the recipients.

Better use after update business rule on your table with proper conditions, event on your table and then trigger the notification via event using eventQueue()

I hope you can do that.

Ensure Event parm1 contains recipient = True in notification

BR script

    var recipients = [];
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('group', current.assignment_group);
    gr.addEncodedQuery("user.roles=itil");
    gr.query();
    while (gr.next()) {
        recipients.push(gr.user.toString());
    }
    gs.eventQueue('event_name', current, recipients.toString());

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

5 REPLIES 5

Hello @Ankur Bawiskar 
No, we can't use directly email script  " email.setRecipients ".
Thank you