How to set notification preferences for all users are same as per their role.

mmr
Tera Contributor

Hi Team,

We would like to set same notification preferences for all users based on their role. When I checked in Roles and groups forms, did not find any option to configure preferences in roles or groups. So here do we need to achieve this by writing some scripting? please suggest on this.

11 REPLIES 11

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Mohana,



Notification preferences is controlled based on user level. You can use Business rule on table "sys_audit_role" or "sys_user_has_role_list" and insert record as per your req.


I don't have script handy with me but myself or chuck will help you out if you are blocked.



P.S : I am not sure if creating a BR on "sys_audit_role" might have any performance impact.


Hi Pradeep,


Thank you for the information on this. Yes, we need to take care of the performance as well. So just trying to get more information on this task.


I have communicated with the user and information on this as this functionality was not provided bydefault with the Out-of-Box, we need to customize this if we want to set notification preferences same for all the users as per their role. It looks the better way to work on this is to writer BR on sys_user_has_role_list to get the roles to compare. Please assist on this if you have any other thoughts. Thanks in advance.


Chuck Tomasi
Tera Patron

Hi Mohana,



You'll find entries in cmn_notif_messages. Identify which users get which notifications by creating records for those users. User is a sys_user reference field and Notification points to sysevent_email_action (notifications).



find_real_file.png


Something like this:



var userList = [userid1, userid2, userid3]; // Sample user IDs


var notificationList = [nId1, nId2, nId3]; // List of notifications to subscribe to



for (var i = 0; i < userList.length; i++) {


      for (j = 0; j < notificationList.length; j++) {


                  var n = new GlideRecord('cmn_notif_messages');


                  n.newRecord();


                  n.user = userList[i];


                  n.notification = notificationList[j];


                  n.update(); // update will create a new record if it doesn't already exist


      }


}


mmr
Tera Contributor

Thank you for the reply with the information on this. Gone through your sample script, it looks the user id's and notification list has defined manually in the script. Hope it should be dynamic to apply for the users and notifications based on roles. Trying to get detailed information to complete this task, because here we would like to configure the notification preferences based on their role. Requesting to provide some more information in details which will helpful to complete this.


Appreciate your assistance in advance.


Hi Chuck,

Notification Preferences option is not coming inside a user's record Related Link view, any suggestions how can I achieve this ?

find_real_file.png