Skip to main content

Do After Delete

Last updated 2/04/2026

Overview

The Do After Delete event is a server-side event that executes immediately after a record has been successfully deleted and committed to the database. It allows you to perform actions that depend on the record no longer existing in the database.

The event provides access to the

old
object on the
context
parameter, this is the record as it existed before it was deleted.

How it Works

When a record is deleted:

  1. The Do After Delete event executes on the server after the deletion is committed to the database.
  2. The
    old
    object contains the values of the record before it was deleted.
  3. The record is no longer accessible in the database at this stage.
  4. Any changes made to the
    old
    object will not affect the database.
  5. You can use the
    old
    object to trigger follow-up logic based on the deleted data.

Use Cases

  • Log deletions for audit or compliance purposes
  • Remove or clean up related records in other tables
  • Trigger notifications when a record is deleted
  • Update aggregates or counts affected by the deletion

Example

This function runs after deleting a customer record and logs the deletion in an audit table.

JavaScript
Log record deletion after database removal
// Log record deletion after it has been removed
function doAfterDelete(five, context, result) {
const oldRecord = context.old;

const query = `
INSERT INTO AuditLog (RecordID, FieldName, OldValue, NewValue, ChangedAt)
VALUES (?, ?, ?, ?, ?)
`;

five.executeQuery(
query,
0,
oldRecord.ID,
'Record Deleted',
JSON.stringify(oldRecord),
null,
five.now()
);

return five.success();
}