Comment notification for selected user and group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
17m ago
Hi @nandini29 ,
Please find the script -
// Add group members
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group', current.cat_item.group);
gr.query();
while (gr.next()) {
if (gr.user.email) {
email.addAddress('to', gr.user.email.toString(), gr.user.name.toString());
gs.info('Group Email Sent to: ' + gr.user.email);
} else {
gs.info('No email for group user: ' + gr.user.name);
}
}
// Add selected users from list collector
var users = current.variables.select_list_of_users_to_send_emails;
if (users) {
var user = new GlideRecord('sys_user');
user.addEncodedQuery('sys_idIN' + users);
user.query();
while (user.next()) {
if (user.email) {
email.addAddress('to', user.email.toString(), user.name.toString());
gs.info('User Email Sent to: ' + user.email);
} else {
gs.info('No email for selected user: ' + user.name);
}
}
} else {
gs.info('No users selected in list collector');
}
NOTE -
- Check the mail script logs in System Logs → All using your gs.info() tags.
please mark it as complete and close the thread if this resolves your issue
Thanks,
Rithika.ch