Sub-Workflows နှင့် Reusability
Sub-Workflow ဆိုတာ ဘာလဲ?
Section titled “Sub-Workflow ဆိုတာ ဘာလဲ?”Sub-Workflow ဆိုတာ Main Workflow တစ်ခုမှ တခြား Workflow တစ်ခုကို ခေါ်သည့် Pattern ပါ။ Programming ၏ Function ကဲ့သို့ — တစ်ကြိမ် ဖန်တီးပြီး နေရာများစွာ Reuse လုပ်နိုင်သည်။
Sub-Workflow မသုံးပါက Email Logic, Slack Logic, Notion Logic စသည်တို့ကို Workflow တစ်ခုစီမှာ ထပ်ထပ်ရေးရသည် (Code Duplicated)။ Sub-Workflow သုံးပါက “Email Sub-WF” တစ်ခုတည်း ဆောက်ပြီး Order Workflow, Invoice Workflow, Reminder Workflow မှ Reuse လုပ်နိုင်သည် (DRY Principle)။
Sub-Workflow ဖန်တီးနည်း
Section titled “Sub-Workflow ဖန်တီးနည်း”Step 1: Reusable Workflow ဆောက်ပါ
Section titled “Step 1: Reusable Workflow ဆောက်ပါ”“Send Notification” Sub-Workflow တစ်ခု ဆောက်မည်:
Sub-Workflow ၏ နောက်ဆုံးမှာ “Set: Return Result” Node ထည့်ပြီး Caller ကို Result ပြန်ပို့ပါ။
Execute Workflow Trigger Node — Manual Trigger အစား ဤ Node ကို Sub-Workflow ထဲ သုံးသည်:
Expected Input (what main workflow sends):{ "channel": "slack", // or "email" "message": "...", "recipient": "...", "subject": "..." // for email only}Step 2: Main Workflow မှ ခေါ်ပါ
Section titled “Step 2: Main Workflow မှ ခေါ်ပါ”Main Workflow ထဲ “Execute Workflow” Node ကို ထည့်ပါ:
Main Workflow မှ Sub-Workflow ကို ခေါ်ခြင်း
Execute Workflow Node Configuration:
- Workflow: [Send Notification]
- Mode: Run once with all items
- Input Data:
| Field | Value |
|---|---|
| channel | slack |
| message | {{ $json.orderSummary }} |
| recipient | #orders |
Common Sub-Workflow Patterns
Section titled “Common Sub-Workflow Patterns”Pattern 1: Shared Utility
Section titled “Pattern 1: Shared Utility”Utility Sub-Workflows:
- “Format Myanmar Phone Number” — +959… format
- “Validate Email Address” — Format + MX check
- “Calculate Tax” — MMK tax calculation
- “Generate Unique ID” — UUID / Ticket number
“Format Phone Number” Sub-Workflow:
// Code Node in Sub-Workflowconst phone = $input.first().json.phone;
// Remove non-digitslet clean = phone.replace(/\D/g, '');
// Add Myanmar country code if missingif (clean.startsWith('09')) { clean = '+959' + clean.slice(2);} else if (!clean.startsWith('959')) { clean = '+959' + clean;} else { clean = '+' + clean;}
return [{ json: { formattedPhone: clean, original: phone } }];Pattern 2: API Client Sub-Workflow
Section titled “Pattern 2: API Client Sub-Workflow”API Credential နှင့် Logic ကို တစ်နေရာတည်း ထားသည်:
Sub-Workflow: "Shopify: Get Orders"
Main Workflow မှ:
[Execute Workflow: "Shopify: Get Orders"] Input: { status: "pending", limit: 50 } │ ▼[Process each order...]Pattern 3: Parallel Sub-Workflow Execution
Section titled “Pattern 3: Parallel Sub-Workflow Execution”Multiple Items ကို Parallel ဖြင့် Process:
100 Customers ကို Batch 10 ခုခွဲပြီး Parallel Process လုပ်သည်
Execution Modes
Section titled “Execution Modes”Execute Workflow Node ၌ Execution Mode ၂ ခု ရှိသည်:
Mode 1: “Run once with all items”
- Sub-workflow ကို တစ်ကြိမ်သာ ခေါ်ပြီး Items အားလုံးကို တစ်ခေါ်တည်း ပို့သည်
- Batch Processing အတွက် ကောင်းသည်
Mode 2: “Run once for each item”
- Item တစ်ခုချင်းစီအတွက် Sub-workflow ကို တစ်ကြိမ်စီ ခေါ်သည်
- Individual Item Processing အတွက် ကောင်းသည်
Workflow Organization — Best Practices
Section titled “Workflow Organization — Best Practices”Naming Convention
Section titled “Naming Convention”Good Naming:✅ "Core: Send Email Notification"✅ "Integration: Shopify Get Orders"✅ "Utility: Validate & Format Phone"✅ "Daily: Morning Report"
Bad Naming:❌ "Workflow 1"❌ "test"❌ "new workflow copy (2)"Folder Structure
Section titled “Folder Structure”n8n Workflows Organization:
- Core (Sub-workflows) — Send Notification, Log to Database, Send Error Alert
- Integrations — Shopify: Sync Orders, Google Sheets: Update, Notion: Add Record
- Scheduled — Daily: Morning Report, Weekly: Digest Email, Monthly: Invoice
- Triggers — Webhook: Contact Form, Webhook: Payment, Webhook: GitHub Push
Sub-Workflow vs Inline Logic
Section titled “Sub-Workflow vs Inline Logic”| Sub-Workflow | Inline | |
|---|---|---|
| Reuse | ✅ Multiple workflows | ❌ One workflow only |
| Maintenance | ✅ Update once | ❌ Update everywhere |
| Testing | ✅ Test independently | ❌ Must test in context |
| Complexity | ❌ Extra setup | ✅ Simpler |
| Performance | ❌ Slightly slower | ✅ Faster |
Complete Production Workflow Example
Section titled “Complete Production Workflow Example”E-Commerce Order Processing (Production Ready):
Course ပြီးဆုံးသွားပြီ!
Section titled “Course ပြီးဆုံးသွားပြီ!”ဤ Course တွင် လေ့လာခဲ့သောအရာများ:
- ✅ n8n ဆိုတာ ဘာလဲ — Automation Tool Overview
- ✅ Installation & Setup — Local မှာ Run နည်း
- ✅ Nodes & Workflows — Core Building Blocks
- ✅ Triggers & Events — Workflow Start Conditions
- ✅ Credentials — API Authentication
- ✅ HTTP Request & Webhook — API Integration
- ✅ Data Transformation — IF, Switch, Code, Set
- ✅ Email & Notification Automation
- ✅ Real-world API Integration
- ✅ Error Handling — Production-ready Workflows
- ✅ Sub-Workflows — Modular & Reusable Patterns
Next Steps:
- n8n Template Library ကို Browse ပြုလုပ်ပါ — community.n8n.io
- ကိုယ်ပိုင် Automation Idea တစ်ခု ဆောက်ကြည့်ပါ
- n8n Self-host on VPS/Cloud ကို Deploy လုပ်ကြည့်ပါ