The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Comment notification for selected user and group

nandini29
Tera Contributor

Hi all,

Requirement: Notification need to be sent for the selected user and groups when comment is added to the RITM

For selected user there a variable with type list collector defined in the catalog item , when form is submitted if comment is updated for the RITM notification need to be sent to selected user and group

I am using mail script for this, through which will be define the mail script in the notification on what it will contain tab

 gs.info('07d5719847d436543c68304b116d4365xyz');

    var gr = new GlideRecord('sys_user_grmember');

    gr.addQuery('group', current.cat_item.group);

    gr.query();

    while (gr.next()) {

        email.addAddress('to', gr.user.email.toString(), gr.user.name.toString());

 

    }

    var users = current.variables.select_list_of_users_to_send_emails;

    var user = new GlideRecord('sys_user');

 

    user.addEncodedQuery('sys_idIN' + users);

    user.query();

    while (user.next()) {

        gs.info('07d5719847d436543c68304b116d4365' + user.email.toString());

        email.addAddress('to', user.email.toString(), user.name.toString());

 

    }


The above script I am using, in logs user id are fetching but email is not triggering, any suggestions on this please

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@nandini29 

you should use gs.eventQueue() based approach and use business rule for this

1) create event on RITM table

2) create after update BR on RITM table

Condition: current.cat_item.name == 'Your Item Name' && Comments Changes

Script:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var group = current.cat_item.group.email.toString();
    var listCollectorUsers = current.variables.select_list_of_users_to_send_emails.toString();

    var recipient = group + ',' + listCollectorUsers;

    gs.eventQueue('eventName', current, recipient);

})(current, previous);

3) Notification on RITM table and link it with event created in 1st step

a) Event parm1 contains Recipient - True

b) Have your subject and email body

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