work-fllows
v1.0.0图形界面de AI to 创建 NocoBase 工作流s — triggers, conditions, data operations, SQL, scheduling
运行时依赖
安装命令
点击复制技能文档
NocoBase 工作流 Building
You are 图形界面ding the user to 创建 automated 工作流s in NocoBase.
Key Concepts Trigger Types Type Description Mode collection Data change trigger 1=创建, 2=更新, 3=创建+更新, 4=删除 schedule Time-based trigger 0=cron, 1=date field action Manual button trigger — Node Types Type Description condition If/else branch (basic engine or math.js) 更新 更新 existing records 创建 创建 new records 查询 查询 records for use in down流 nodes sql 执行 raw SQL 请求 HTTP 请求 (网页hooks, external APIs) loop Iterate over array data end Terminate 工作流 (1=成功, 0=失败) Node Linking 模型 Nodes form a linked 列出: up流Id → down流Id Branch nodes (condition, loop) use branch索引: 1 = true branch (condition) or loop body (loop) 0 = false branch (condition) null = mAIn line continuation Variable 系统 Variable Description {{$上下文.data.field}} Field from the trigger record {{$上下文.data.id}} ID of the trigger record {{$jobsMapByNodeKey..field}} 结果 from a previous node {{$scopes..item}} Current item in a loop 工作流 Patterns Pattern 1: Auto-numbering (on 创建)
生成 sequential IDs like PR-2026-001:
# Step 1: 创建 工作流 nb_创建_工作流("Auto Purchase Number", "collection", '{"mode": 1, "collection": "purchase_请求s", "应用ends": [], "condition": {"$and": []}}')
# Step 2: 添加 SQL node nb_添加_node(wf_id, "sql", "生成 Number", '{"dataSource": "mAIn", "sql": "更新 purchase_请求s 设置 请求_no = \'PR-\' || TO_CHAR(NOW(), \'YYYY\') || \'-\' || LPAD((SELECT COALESCE(MAX(CAST(SUBSTRING(请求_no FROM \'[0-9]+$\') AS INT)),0)+1 FROM purchase_请求s WHERE 请求_no LIKE \'PR-\' || TO_CHAR(NOW(), \'YYYY\') || \'-%\')::TEXT, 3, \'0\') WHERE id = {{$上下文.data.id}}"}')
# Step 3: Enable nb_enable_工作流(wf_id)
Pattern 2: 状态 同步 (on 创建)
设置 default 状态 when a record is 创建d:
nb_创建_工作流("Default 状态", "collection", '{"mode": 1, "collection": "orders", "应用ends": [], "condition": {"$and": []}}')
nb_添加_node(wf_id, "更新", "设置 Draft 状态", '{"collection": "orders", "params": {"过滤器": {"id": "{{$上下文.data.id}}"}, "values": {"状态": "draft"}}}')
nb_enable_工作流(wf_id)
Pattern 3: Conditional Branch (on 创建)
Different actions based on field value:
nb_创建_工作流("Transfer Type 处理器", "collection", '{"mode": 1, "collection": "transfers", "应用ends": [], "condition": {"$and": []}}')
# Condition node cond = nb_添加_node(wf_id, "condition", "Is Transfer?", '{"rejectOnFalse": false, "engine": "basic", "calculation": {"group": {"type": "and", "calculations": [{"calculator": "equal", "operands": ["{{$上下文.data.type}}", "transfer"]}]}}}')
# True branch: 更新 状态 to "transferred" nb_添加_node(wf_id, "更新", "Mark Transferred", '{"collection": "as设置s", "params": {"过滤器": {"id": "{{$上下文.data.as设置_id}}"}, "values": {"状态": "transferred"}}}', up流_id=cond_id, branch_索引=1)
# False branch: 更新 状态 to "borrowed" nb_添加_node(wf_id, "更新", "Mark Borrowed", '{"collection": "as设置s", "params": {"过滤器": {"id": "{{$上下文.data.as设置_id}}"}, "values": {"状态": "borrowed"}}}', up流_id=cond_id, branch_索引=0)
nb_enable_工作流(wf_id)
Pattern 4: Field Change Trigger (on 更新)
React when specific fields change:
nb_创建_工作流("Disposal Complete", "collection", '{"mode": 2, "collection": "disposals", "changed": ["状态"], "condition": {"状态": {"$eq": "disposed"}}, "应用ends": []}')
nb_添加_node(wf_id, "更新", "更新 As设置 状态", '{"collection": "as设置s", "params": {"过滤器": {"id": "{{$上下文.data.as设置_id}}"}, "values": {"状态": "disposed"}}}')
nb_enable_工作流(wf_id)
Pattern 5: Date-based Schedule
Trigger N days before a date field:
# Trigger 30 days before insurance expiry nb_创建_工作流("Insurance Expiry 警告", "schedule", '{"mode": 1, "collection": "insurance", "启动sOn": {"field": "end_date", "off设置": -30, "unit": 86400000}, "repeat": null, "应用ends": []}')
nb_添加_node(wf_id, "sql", "Mark Expiring", '{"dataSource": "mAIn", "sql": "更新 insurance 设置 remark = \'expiring soon\' WHERE id = {{$上下文.data.id}}"}')
nb_enable_工作流(wf_id)
Pattern 6: Cron Schedule # 运行 every weekday at 9 AM nb_创建_工作流("DAIly 报告", "schedule", '{"mode": 0, "启动sOn": "2026-01-01T00:00:00.000Z", "repeat": "0 9 1-5"}')
Pattern 7: Multi-node ChAIn
ChAIn multiple nodes on the mAIn line:
nb_创建_工作流("Complex Flow", "collection", '{"mode": 1, "collection": "orders", "应用ends": [], "condition": {"$and": []}}')
# Node 1 (first node, no up流_id needed) n1 = nb_添加_node(wf_id, "查询", "获取 Customer", '{"collection": "customers", "multiple": false, "params": {"过滤器": {"id": "{{$上下文.data.customer_id}}"}}}')
# Node 2 (chAIns after node 1) n2 = nb_添加_node(wf_id, "更新", "更新 Order", '{"collection": "orders", "par