How to disable email notifications by default for specific SLA until users subscribe from their profile?

adarsh-homepage
Kilo Contributor

We are setting up a response SLa. However we do not want people to receive email notifications by default.They should only get it if they subscribe for it.

We have not put anyone in users/user&groups fields/groups.

We see in outbound that email is sent to everyone in that assignment group where ticket is assigned.

4 REPLIES 4

vijivt
Mega Expert

Hi adarsh-homepage,



You can access the subscription based notifications from a user record and you can add or remove notifications


User Administration > Users


Related Links > Notification Preferences



Please go through the wiki link for more details : Setting Up Subscription Based Notifications - ServiceNow Wiki


Thank Viji,



This option will be helpful to disable the notifications once it is added to users profile. However, we want it to be disabled by default and no user should receive those SLA timer notifications(For eg: 30 minutes, 60 minutes so on...). If any user needs to receive that notification it should then be triggered to their mailbox.


Brian Dailey1
Kilo Sage

Hi Adarsh,



To manage Subscribed Notifications, a user normally has to have received the notification message (e.g., "Incident Assigned to You") AT LEAST ONCE to be managed through the Notification Preferences link.   That sets up a record in the table [cmn_notif_message] relating the user to that particular notification for it to be managed.



However, to initially opt-out all users from getting all messages initially, you could insert a record for each user for each notification by script into the table [cmn_notif_message] and set the field 'notification_filter' to the option for "Unsubscribe".   The values for 'notification_filter' are stored in the table [notification_filter]... so you will need to go to this table and copy the sys_id of the record for the "Unsubscribe" option to use in your script.



Your Notifications are stored in the table [sysevent_email_action], you would need to loop through all these records to setup the entries for each user.




So... for a one-time setup from a script on a particular user, say from Business Rule on [sys_user] at Insert:



        var grMessages = new GlideRecord('sysevent_email_action');


        while(grMessages.next()){


                  var grSubscription = new GlideRecord('cmn_notif_message');


                  grSubscription.initialize();


                  grSubscription.notification = grMessages.sys_id;


                  grSubscription.user = current.sys_id;


                  grSubscription.filter = '(sys_id of your Unsubscribe filter option)';


                  grSubscription.insert();


        }




This will opt-out of all existing notifications for a newly inserted user.




You would need to write some additional code on the Notifications table ([sysevent_email_action]) to account for when new Notifications get added, make a script to create an opt-out record for the one notification for all users... you get the idea, and can extend the code above.   Just flip-flop where you are using a gliderecord and current in the script:



        var grUsers = new GlideRecord('sys_user');


        while(grUsers.next()){


                  var grSubscription = new GlideRecord('cmn_notif_message');


                  grSubscription.initialize();


                  grSubscription.notification = current.sys_id;


                  grSubscription.user = grUsers.sys_id;


                  grSubscription.filter = '(sys_id of your Unsubscribe filter option)';


                  grSubscription.insert();


        }





Good luck,


-Brian




IMPORTANT:   If you implement these as Business Rules, make sure to have them run as AFTER business rules, to ensure that the new record and sys_id exists before you try using it to setup an association.


Sorry, I over generalized that solution to be for ALL notifications.   I'm on a partial-read jag today.



Doing just for your one SLA notification is simpler, just use the second block of code, but insert the sys_id of your SLA notification:



        var grUsers = new GlideRecord('sys_user');


        while(grUsers.next()){


                  var grSubscription = new GlideRecord('cmn_notif_message');


                  grSubscription.initialize();


                  grSubscription.notification = '(sys_id of SLA notification)';


                  grSubscription.user = grUsers.sys_id;


                  grSubscription.filter = '(sys_id of your Unsubscribe filter option)';


                  grSubscription.insert();


        }




Thanks,


-Brian