Blog

User Account Notifications

Sometimes it is helpful to have notifications to activate or deactivate users at your company.  Here are a couple of reasons to do this:

  • Inform the manager of the onboard process for a new employee.  
  • Notify a user know that their account was deactivated or deleted.
  • Let a user know of additional training needed to gain itil role privileges.

Below are some example notifications to get you started:

NOTE: You may need to adjust the conditions that trigger the emails based on types of the user imports you have at your company.  Check the email log to see if the correct number of notifications are occurring.

Example 1: User Activation

Email Notification: 
Name: User Activation
Table: User [sys_user]
When to send: 
Send when: Record is Inserted
Inserted: true
Condition: Active is true AND Active changes
Who will recieve: Manager
What it will contain:
Subject: ServiceNow New User Activation
Message:
User Activation Instructions Here

Example 2: User Deactivation

Notification: User Deactivation
Name: User Deactivation
Table: User [sys_user]
When to send:
Send when: Record is inserted or updated
insert: true
update: true
Condition: Active changes AND Active is false
Who will receive
Send to event creator: true
User: Email
Subject: ServiceNow User Deactivation
User Deactivation Instructions Here

Example 3: User Deletion

This one has a trick to it. Since the record is deleted, you have to go into the sys_audit_delete table and pull your record to send in the event.

Business Rule: User Deleted
Table: User [sys_user]
Order:50
When: after
Delete:true
Condition: 
Script:
findAuditDeleted();
function findAuditDeleted() {
var grAuditDelete = new GlideRecord('sys_audit_delete');
grAuditDelete.addQuery('documentkey', current.sys_id);
grAuditDelete.query();
if (grAuditDelete.next()) {
gs.eventQueue("user.deleted", grAuditDelete, current.email);
}
}

Registry
Event name: user.deleted
Table: Audit Deleted Record [sys_audit_deleted]
Fired by: User Deleted business rule

Notification: User Deleted
Name: User Deleted
Table: Audit Deleted Record [sys_audit_deleted]
When to send:
Send when: event is fired
Event name: user.deleted
Who will recieve (Click advanced view)
Send to event creator: true
Event parm 1 contains recipient: true
Subject: ServiceNow New User Deletion
User Deactivation Instructions Here