Skip to main content

Do After Insert

Last updated 31/03/2026

Overview

The Do After Insert event is a server-side event that executes immediately after a new record has been successfully committed to the database. This event allows you to perform actions that depend on the record already existing in the database.

How it Works

When a new record is inserted:

  1. The Do After Insert event executes on the server after the record is saved.
  2. The
    context
    parameter contains the new record.
  3. Any changes made to the
    new
    object at this stage will not affect the already committed record, but you can use it to perform follow-up operations such as inserts, updates, or notifications.

Use Cases

  • Insert related records in other tables that depend on the new record
  • Send confirmation emails or notifications after a record is saved
  • Trigger workflows or processes that require the record to exist in the database
  • Log audit trails based on the newly inserted record

Example

This function runs after inserting a new customer record and inserts a welcome message into a Messages table for that customer.

JavaScript
Inserts a message in a related table
function doAfterInsert(five, context, result) {
const newRecord = context.new;

// Example: Insert a welcome message for the new customer
const query = `
INSERT INTO Messages (CustomerID, Message, CreatedAt)
VALUES (?, ?, ?)
`;

five.executeQuery(query, 0, newRecord.ID, 'Welcome to our service!', five.now());

return five.success();
}