Skip to main content

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.

Approval Flows ≠ Only for Approvals

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

FeatureDescriptionValue
Auto TriggerAutomatically trigger processes when data changesReduce manual operations, improve efficiency
Conditional LogicSupport precondition expressionsFlexible control of trigger timing
Process IntegrationSeamless integration with approval flow capabilitiesRapidly implement business automation
Multiple TriggersSupport 6 trigger timingsCover complete business scenarios
Resource InvocationCall cloud functions, databases, etc. in approval flowsImplement complex business logic
Prerequisites

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 TimingTrigger ScenarioUse Cases
After CreateTriggered after creating a single recordNew order approval, automatic field calculation, auto-generate numbers, send notifications
After UpdateTriggered after updating a single recordAutomatic field concatenation, data linkage updates, status change approval, logging
After DeleteTriggered after deleting a single recordData deletion approval, cascade delete related data, resource cleanup
After Batch CreateTriggered after batch creating multiple recordsPost-import processing, batch initialization, batch approval
After Batch UpdateTriggered after batch updating multiple recordsBatch data synchronization, batch price adjustment approval, batch status changes
After Batch DeleteTriggered after batch deleting multiple recordsBatch 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:

  1. Visit CloudBase Platform/Data Models
  2. Select the target data model
  3. Enter the "Event Handlers" tab
  4. 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 (true or false)
  • 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.

Capabilities of 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 OptionDescriptionUse Case
After Create ValuePass all fields of the current data recordApproval flow needs to view and process complete data information
NoneDo not pass any dataApproval 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 ItemConfiguration Value
Trigger TimingAfter Create
Precondition Expression#amount > 5000
Approval ProcessLarge Order Approval Process
Process InputAfter 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 ItemConfiguration Value
Trigger TimingAfter Update
Precondition ExpressionoldData.status === '待支付' && data.status === '已完成'
Approval ProcessOrder Completion Approval Process
Process InputAfter 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 ItemConfiguration Value
Trigger TimingAfter Update
Precondition ExpressionNone
Approval ProcessField Auto-Concatenation Process
Process InputAfter Create Value

Approval Flow Configuration (no approval node needed, directly call data model):

  1. Process Start Node: Receive data passed from event handler
    • Input variable is an object, select corresponding data model, named data
  2. Expression Node: Perform expression calculation on data, named newData
    • Expression: #data.fieldB + "-" + #data.fieldC
  3. Update Record Operation Node: Update data record
    • Data record: Select newData, select submit to database
  4. 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
Approval Flows for Automation

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