workflow-creation
Programmatic workflow creation via API/MCP - build complete workflows without the UI editor
Happy Technologies LLC · 已有静态检查记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add Happy-Technologies-LLC/happy-platform-skills --skill workflow-creation技能说明
name: workflow-creation version: 1.0.1 description: Programmatic workflow creation via API/MCP - build complete workflows without the UI editor author: Happy Technologies LLC tags: [admin, workflow, automation, approval, scripting, advanced] platforms: [claude-code, claude-desktop, chatgpt, cursor, any] tools: mcp: - SN-Create-Workflow - SN-Create-Activity - SN-Create-Transition - SN-Publish-Workflow - SN-Create-Record - SN-Update-Record - SN-Query-Table - SN-Execute-Background-Script rest: - /api/now/table/wf_workflow - /api/now/table/wf_workflow_version - /api/now/table/wf_activity - /api/now/table/wf_transition - /api/now/table/wf_condition - /api/now/table/wf_element_definition native: - Bash - Read complexity: advanced estimated_time: 30-90 minutes
Programmatic Workflow Creation
Overview
This skill enables you to create complete ServiceNow workflows entirely via API/MCP without using the visual Workflow Editor. This is essential for:
- Automation pipelines - Create workflows as part of CI/CD deployments
- Templated solutions - Generate standardized workflows from templates
- Mass creation - Build multiple similar workflows programmatically
- Version control - Store workflow definitions as code in Git
- Environment migration - Recreate workflows across instances
Key Discovery: Activities store their logic in the input field as JavaScript code. This enables full programmatic workflow creation by:
- Creating the workflow structure (wf_workflow, wf_workflow_version)
- Creating activities with embedded scripts (wf_activity)
- Linking activities with transitions (wf_transition, wf_condition)
- Publishing the workflow version
Prerequisites
- Roles:
adminorworkflow_admin - Permissions: Write access to workflow tables (wf_*)
- Knowledge: Basic understanding of workflow concepts
- Environment: Development or test instance (never create workflows in production first)
- Related Skills:
admin/update-set-management- Capture workflows in update sets
Table Architecture
Understanding the workflow tables is critical for programmatic creation.
Core Tables
wf_workflow (base definition)
|
+-- wf_workflow_version (published versions)
|
+-- wf_activity (activities with scripts)
| |
| +-- wf_element_definition (activity types)
| +-- wf_stage (optional stages)
|
+-- wf_transition (connects activities)
| |
| +-- wf_condition (transition logic)
|
+-- wf_condition (workflow-level conditions)
Key Relationships
| Table | Purpose | Key Fields |
|---|---|---|
wf_workflow | Base workflow definition | name, table, description |
wf_workflow_version | Versioned workflow | workflow, table, start, published |
wf_activity | Individual activities | workflow_version, input, x, y |
wf_transition | Activity connections | from, to, condition |
wf_condition | Transition conditions | activity, condition, else_flag |
wf_element_definition | Activity type definitions | name, default_input |
Procedure
Step 1: Discover Activity Types
First, identify available activity types (wf_element_definition).
Using MCP:
Tool: SN-Query-Table
Parameters:
table_name: wf_element_definition
query: active=true
fields: sys_id,name,category,description
limit: 50
Common Activity Types:
| sys_id | Name | Use Case |
|---|---|---|
| 0a6c97790a0a0b2756919eb960284334 | Notification | Send email/SMS |
| 1ca8d7cf0a0a0b265e9a000c2c08248c | Set Values | Set field values |
| 35433da80a0a029a0028c639a1e51eb4 | Approval - User | User approval |
| 354e911f0a0a029a00e6a0e6ad74206f | Approval - Group | Group approval |
| 283e8bb80a2581021d036a052ffc3433 | Approval Coordinator | Multi-approval container |
| 38891b6f0a0a0b1e00efdfdd77602027 | Catalog Task | Create catalog task |
| 3961a1da0a0a0b5c00ecd84822f70d85 | Timer | Wait/delay |
| 396807940a0a0b5c00afd9f67d9fd7a2 | Log Message | Debug logging |
| 5994b389c0a80011000e64de81b1864c | Subflow | Call another workflow |
| 7c9a2ba9c0a801650021ada408de0ebd | Join | Wait for multiple paths |
| 7a8ea386c0a80066179bc1f5186e1d2b | Rollback | Go back to earlier activity |
Note: Custom script activities can omit activity_definition entirely.
Step 2: Create Base Workflow
Create the workflow container record.
Using MCP (Preferred):
Tool: SN-Create-Workflow
Parameters:
name: "P1 Incident Auto-Assignment"
table: "incident"
description: "Auto-assign P1 incidents to on-call engineer"
condition: "priority=1^state=1"
Using SN-Create-Record:
Tool: SN-Create-Record
Parameters:
table_name: wf_workflow
data:
name: "P1 Incident Auto-Assignment"
description: "Auto-assign P1 incidents to on-call engineer"
template: false
access: "public"
Important: The name and table fields become read-only after creation. Choose carefully.
Save the sys_id: workflow_sys_id
Step 3: Create Workflow Version
Create a version that holds the actual workflow logic.
Using MCP:
Tool: SN-Create-Record
Parameters:
table_name: wf_workflow_version
data:
name: "P1 Incident Auto-Assignment"
workflow: [workflow_sys_id]
table: "incident"
condition: "priority=1^state=1"
active: true
published: false
order: 100
run_multiple: false
after_business_rules: true
Key Fields:
| Field | Purpose | Notes |
|---|---|---|
table | Target table | REQUIRED - what records trigger this |
condition | Trigger condition | Encoded query format |
active | Is active | Set true for workflow to run |
published | Is published | Set false initially, publish after testing |
run_multiple |