Send Email on Record Delete in ServiceNow

ServiceNow email notification could basically be sent when a record is inserted or updated. How about when a record is deleted? How could we fire an email emanating from a record that is already deleted? Yes, in ServiceNow this is possible using an Event and Business Rule which we will discuss in this piece.

49E75C9D-2303-4118-826F-515FD3CBE8AA.PNG
Open image in new tab to clearly view its content.

Event Registry. Let us start by registering an event in the Event Registry table in order for it to be recognized by the system. In this piece, let us name our Event “demonstration.delete”, and then let us point it to our Demonstration table.

19DFBC55-B474-4D1B-AC41-89A9C6945D52
Open image in new tab to clearly view its content.

Business Rule. Our next step is to create a Business Rule that uses the Event we have just register. Let us name it “Demonstration Delete”, let us point it to our Demonstration table, and then let us set it to run “After Delete”.

66805B70-2E13-4FBA-94A8-D471962E9B31.PNG
Open image in new tab to clearly view its content.

Our next step is write a server-side script in the Advanced tab that gets the information of the deleted record from Audit Deleted Record table and pass it as a GlideRecord parameter in queuing an event through the server-side “eventQueue” method of the GlideSystem API.

Below is the script in the Advanced tab:

var glideDelete = new GlideRecord('sys_audit_delete');
glideDelete.addQuery('documentkey', current.sys_id);
glideDelete.query();

if(glideDelete.next()){
   gs.eventQueue('demonstration.delete', glideDelete, gs.getUserID(), 
   gs.getUserName());
}

We can verify if the event is successfully queued and processed from the Event Log table.

Email Notification. And the final step is the email notification that we need to attach to the Audit Deleted Record table which will be sent when our “demonstration.delete” event is fired.

947FE3F5-F300-42B7-A05A-07032516FCE2.PNG
Open image in new tab to clearly view its content.

Hope this helps.

Leave a comment