Skip to main content

Do After Update

Last updated 1/04/2026

Overview​

The Do After Update event is a server-side event that executes immediately after an existing record has been successfully updated and committed to the database. It allows you to perform actions that depend on the updated data already existing in the database.

The event provides access to two objects on the

context
parameter:

  • old
    - the existing record currently stored in the database
  • new
    - the record as it exists after the update

By comparing these two objects, you can perform follow-up operations.

How it Works​

When a record is updated:

  1. The Do After Update event executes on the server after the changes are committed to the database.
  2. The
    old
    object contains the values stored in the database before the update.
  3. The
    new
    object contains the updated values that have just been committed.
  4. Any changes made to the
    new
    object at this stage will not affect the already committed record.
  5. You can compare the
    old
    and
    new
    objects to detect what has changed and trigger follow-up logic

Use Cases​

  • Log changes for audit purposes by comparing old and new values
  • Trigger notifications or emails when fields are updated
  • Update related records in other tables based on changes
  • Trigger workflows that rely on the updated record

Example​

This function runs after updating a customer record, checks if the status field changed, and logs the change in an audit table.

JavaScript
Log status changes after record update
function doAfterUpdate(five, context, result) {
const oldRecord = context.old;
const newRecord = context.new;

// Log status change
if (oldRecord.Status !== newRecord.Status) {
const query = `
INSERT INTO AuditLog (RecordID, FieldName, OldValue, NewValue, ChangedAt)
VALUES (?, ?, ?, ?, ?)
`;

five.executeQuery(
query,
0,
newRecord.ID,
'Status',
oldRecord.Status,
newRecord.Status,
five.now()
);
}

return five.success();
}