diff --git a/Server-Side Components/Business Rules/Disable Notification Devices and Subscription on user deactivation/disableNotifDevices.js b/Server-Side Components/Business Rules/Disable Notification Devices and Subscription on user deactivation/disableNotifDevices.js new file mode 100644 index 0000000000..ab8a62a74b --- /dev/null +++ b/Server-Side Components/Business Rules/Disable Notification Devices and Subscription on user deactivation/disableNotifDevices.js @@ -0,0 +1,26 @@ +(function executeRule(current, previous /*null when async*/ ) { + + var currentUserId = current.getUniqueValue(); + + var notifDevice = new GlideRecord('cmn_notif_device'); + notifDevice.addQuery('user', currentUserId); + notifDevice.addQuery('active', true); + notifDevice.query(); + while (notifDevice.next()) { + notifDevice.active = false; + notifDevice.update(); + } + + + var notifSubs = new GlideRecord('sys_notif_subscription'); + notifSubs.addQuery('user', currentUserId); + notifSubs.addQuery('active', true); + notifSubs.query(); + while (notifSubs.next()) { + notifSubs.active = false; + notifSubs.update(); + } + + + +})(current, previous); diff --git a/Server-Side Components/Business Rules/Disable Notification Devices and Subscription on user deactivation/readme.md b/Server-Side Components/Business Rules/Disable Notification Devices and Subscription on user deactivation/readme.md new file mode 100644 index 0000000000..6eb416fed9 --- /dev/null +++ b/Server-Side Components/Business Rules/Disable Notification Devices and Subscription on user deactivation/readme.md @@ -0,0 +1,20 @@ +This onAfter business rule script checks for the inactivated user and then disables the notification devices and Notification +subscriptions of that particular user. + +This help us to keep the data aligned, prevent any unnecessary notifications or triggers and enhances data management. It will +also eliminate the manual efforts. + + +Business Rule Setup: +1. Name: Manage Inactive user Notif Devices [Amend it as suitable] +2. Table: [sys_user] +3. When to run: 'After' 'Update' +4. Condition: 'Active' 'Changes to' 'False' + + +image + + +5. In 'Advanced' section: Paste the script of [disableNotifDevices.js] + +image