Skip to main content

Entity Lifecycle Hook - After Create with Queue Integration

Description

This automation demonstrates entity lifecycle hooks that trigger after record creation. The automation shows how to chain multiple actions including field auto-generation, related record creation, and message queue integration. This pattern is fundamental for implementing business logic that should execute automatically when new records are created, such as generating sequential numbers, creating dependent records, and triggering asynchronous processes.

Use Case

Used in an arborist job management system to automatically initialize new jobs. When a job is created, the system generates a unique job number based on timestamp, creates the first assessment record for the job, and can trigger additional downstream processes. This ensures data consistency and reduces manual data entry.

Key Features

  • Triggers immediately after entity creation
  • Access to newly created entity data
  • Multiple action execution in sequence
  • Auto-generation of unique identifiers
  • Automatic creation of related records
  • Parameter passing between trigger and actions

JSON Definition

{
"key": "job__afterCreate",
"name": "After job is created",
"entityKey": "job",
"app": "jobs",
"triggerType": "afterCreate",
"triggerParams": {},
"actions": [
{
"name": "autogenerate_number_field_value",
"key": "autogenerate_number_field_value",
"actionTypeKey": "autogenerate_job_number_field_value",
"params": {
"id": "{{trigger.entity.id}}",
"createdAt": "{{trigger.entity._created_at}}"
}
},
{
"name": "Autocreate first job assessment",
"key": "autocreate_first_job_assessment",
"actionTypeKey": "autocreate-first-job-assessment",
"params": {
"jobId": "{{trigger.entity.id}}"
}
}
]
}

Notes

  • The afterCreate trigger fires synchronously after database insert
  • Entity data is available through trigger.entity
  • System fields like _created_at are accessible with underscore prefix
  • Actions execute in the order they are defined
  • Failed actions can prevent subsequent actions from running
  • This pattern ensures data integrity through atomic operations
  • Auto-generated values should be indexed for performance