-
Notifications
You must be signed in to change notification settings - Fork 907
Disable Notification Devices on Deactivation of User #1758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you expecting multiple results? If you only expect one record, it is more efficient to fetch that 1 record. |
||
| notifDevice.active = false; | ||
| notifDevice.update(); | ||
| } | ||
|
|
||
|
|
||
| var notifSubs = new GlideRecord('sys_notif_subscription'); | ||
| notifSubs.addQuery('user', currentUserId); | ||
| notifSubs.addQuery('active', true); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| notifSubs.query(); | ||
| while (notifSubs.next()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you expecting multiple results? If you only expect one record, it is more efficient to fetch that 1 record. |
||
| notifSubs.active = false; | ||
| notifSubs.update(); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| })(current, previous); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notifications will not trigger for inactive users. |
||
| 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' | ||
|
|
||
|
|
||
| <img width="1619" height="517" alt="image" src="https://github.com/user-attachments/assets/428b706e-0aee-4b08-9028-58d309bb8c90" /> | ||
|
|
||
|
|
||
| 5. In 'Advanced' section: Paste the script of [disableNotifDevices.js] | ||
|
|
||
| <img width="859" height="682" alt="image" src="https://github.com/user-attachments/assets/98ad7122-56ad-48d8-8f1a-43a4727d0ead" /> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be combined in an an addActiveQuery: https://www.servicenow.com/docs/bundle/yokohama-api-reference/page/app-store/dev_portal/API_reference/GlideRecord/concept/c_GlideRecordAPI.html#title_r_GlideRecord-AddActiveQuery