Event Handlers
The "Event Handlers" feature of data models is equivalent to database trigger capabilities, allowing you to automatically trigger approval workflows based on data CRUD operations, enabling automation and standardized management of business processes.
Although named "approval flows," they are actually a complete business process orchestration platform that can:
- ✅ Approval scenarios: Order approval, employee onboarding approval, and other scenarios requiring human decision-making
- ✅ Automation scenarios: Automatic field concatenation, data linkage updates, automatic notifications, and other scenarios without human intervention
- ✅ Hybrid scenarios: Automatically process data first, then submit for approval
Essence: Event Handlers + Approval Flows = Database Triggers + Workflow Engine
Core Features
| Feature | Description | Value |
|---|---|---|
| Auto Trigger | Automatically trigger processes when data changes | Reduce manual operations, improve efficiency |
| Conditional Logic | Support precondition expressions | Flexible control of trigger timing |
| Process Integration | Seamless integration with approval flow capabilities | Rapidly implement business automation |
| Multiple Triggers | Support 6 trigger timings | Cover complete business scenarios |
| Resource Invocation | Call cloud functions, databases, etc. in approval flows | Implement complex business logic |
Before using event handlers, please ensure:
- CloudBase Enterprise Edition or above is enabled (required for approval flows)
- Data models and approval processes have been created
- Understand basic approval flow concepts, refer to Approval Flow Usage Guide
Trigger Timings
"Event Handlers" support 6 data operation trigger timings, which can be flexibly selected according to business needs:
| Trigger Timing | Trigger Scenario | Use Cases |
|---|---|---|
| After Create | Triggered after creating a single record | New order approval, automatic field calculation, auto-generate numbers, send notifications |
| After Update | Triggered after updating a single record | Automatic field concatenation, data linkage updates, status change approval, logging |
| After Delete | Triggered after deleting a single record | Data deletion approval, cascade delete related data, resource cleanup |
| After Batch Create | Triggered after batch creating multiple records | Post-import processing, batch initialization, batch approval |
| After Batch Update | Triggered after batch updating multiple records | Batch data synchronization, batch price adjustment approval, batch status changes |
| After Batch Delete | Triggered after batch deleting multiple records | Batch cleanup approval, batch archiving, batch delisting |
⚠️ Note: Trigger timings execute after data operations are completed, when data has already been written to the database
Configuration Steps
Step 1: Create Event Handler
On the data model's event handler page, click the "Create Event Handler" button:
- Visit CloudBase Platform/Data Models
- Select the target data model
- Enter the "Event Handlers" tab
- Click the "Create Event Handler" button
Step 2: Configure Precondition Expression
The "precondition expression" is used to determine whether to execute the event handler. If all triggers are needed, no expression configuration is required.
- Return Value Requirement: Must return a boolean value (
trueorfalse) - Return
true: Condition met, trigger approval flow - Return
false: Condition not met, skip execution
Step 3: Select Process and Set Input Parameters
"Process input parameters" are used to pass data to the approval process, which can make approval decisions and displays based on this data. Go to CloudBase Platform/Approval Flows to create approval flows.
Approval flows are not just simple approval functions, they are a complete business process orchestration platform, supporting:
- Approval Decisions: Multi-level approval, conditional approval, countersigning/or-signing, etc.
- Business Logic: Call cloud functions to execute complex calculations and data processing
- Data Operations: Read/write databases, update data models
- External Integration: Call third-party APIs, send notification messages
- Process Control: Conditional branches, loops, parallel execution, etc.
This means event handlers triggered approval flows can implement various scenarios from simple approvals to complex business automation.
Input Parameter Options
| Input Option | Description | Use Case |
|---|---|---|
| After Create Value | Pass all fields of the current data record | Approval flow needs to view and process complete data information |
| None | Do not pass any data | Approval flow doesn't need data, only for notification or simple approval |
Usage Examples
Example 1: Order Amount Approval
Business Scenario: When order amount amount exceeds 5000, automatically trigger approval process
Configuration:
| Configuration Item | Configuration Value |
|---|---|
| Trigger Timing | After Create |
| Precondition Expression | #amount > 5000 |
| Approval Process | Large Order Approval Process |
| Process Input | After Create Value |
Effect:
- Create order with amount ≤ 5000: No approval triggered, directly created successfully
- Create order with amount > 5000: Automatically trigger approval flow, wait for approval completion
Example 2: Order Status Change Approval
Business Scenario: When order status changes from "Pending Payment" to "Completed", trigger approval process
Configuration:
| Configuration Item | Configuration Value |
|---|---|
| Trigger Timing | After Update |
| Precondition Expression | oldData.status === '待支付' && data.status === '已完成' |
| Approval Process | Order Completion Approval Process |
| Process Input | After Create Value |
Effect:
- Only trigger approval when order status changes from "Pending Payment" to "Completed"
- Other status changes do not trigger approval
Example 3: Automatic Field Concatenation (Automation Scenario)
Business Scenario: When Field C (text) changes, automatically concatenate Field B (auto-number) and Field C with a dash, and update to Field A
Configuration:
| Configuration Item | Configuration Value |
|---|---|
| Trigger Timing | After Update |
| Precondition Expression | None |
| Approval Process | Field Auto-Concatenation Process |
| Process Input | After Create Value |
Approval Flow Configuration (no approval node needed, directly call data model):
- Process Start Node: Receive data passed from event handler
- Input variable is an object, select corresponding data model, named
data
- Input variable is an object, select corresponding data model, named
- Expression Node: Perform expression calculation on data, named
newData- Expression:
#data.fieldB + "-" + #data.fieldC
- Expression:
- Update Record Operation Node: Update data record
- Data record: Select
newData, select submit to database
- Data record: Select
- Process End
Effect:
- When the value of Field C changes, automatically trigger the process
- The process gets the current data record, calculates the value of Field A through expression, and updates the data record
- No manual approval needed, fully automated execution
This example demonstrates that approval flows are not only for approval scenarios, but also for data automation processing:
- Can directly call data models to perform CRUD operations
- Can call cloud functions to execute complex logic
- Can call third-party APIs to implement system integration
- The entire process requires no approval nodes, executes instantly and automatically