servicenow-mcp-server 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/.claude/settings.local.json +70 -0
  2. package/CLAUDE.md +777 -0
  3. package/LICENSE +21 -0
  4. package/README.md +562 -0
  5. package/assets/logo.svg +385 -0
  6. package/config/servicenow-instances.json.example +28 -0
  7. package/docs/403_TROUBLESHOOTING.md +329 -0
  8. package/docs/API_REFERENCE.md +1142 -0
  9. package/docs/APPLICATION_SCOPE_VALIDATION.md +681 -0
  10. package/docs/CLAUDE_DESKTOP_SETUP.md +373 -0
  11. package/docs/CONVENIENCE_TOOLS.md +601 -0
  12. package/docs/CONVENIENCE_TOOLS_SUMMARY.md +371 -0
  13. package/docs/FLOW_DESIGNER_GUIDE.md +1021 -0
  14. package/docs/IMPLEMENTATION_COMPLETE.md +165 -0
  15. package/docs/INSTANCE_SWITCHING_GUIDE.md +219 -0
  16. package/docs/MULTI_INSTANCE_CONFIGURATION.md +185 -0
  17. package/docs/NATURAL_LANGUAGE_SEARCH_IMPLEMENTATION.md +221 -0
  18. package/docs/PUPPETEER_INTEGRATION_PROPOSAL.md +1322 -0
  19. package/docs/QUICK_REFERENCE.md +395 -0
  20. package/docs/README.md +75 -0
  21. package/docs/RESOURCES_ARCHITECTURE.md +392 -0
  22. package/docs/RESOURCES_IMPLEMENTATION.md +276 -0
  23. package/docs/RESOURCES_SUMMARY.md +104 -0
  24. package/docs/SETUP_GUIDE.md +104 -0
  25. package/docs/UI_OPERATIONS_ARCHITECTURE.md +1219 -0
  26. package/docs/UI_OPERATIONS_DECISION_MATRIX.md +542 -0
  27. package/docs/UI_OPERATIONS_SUMMARY.md +507 -0
  28. package/docs/UPDATE_SET_VALIDATION.md +598 -0
  29. package/docs/UPDATE_SET_VALIDATION_SUMMARY.md +209 -0
  30. package/docs/VALIDATION_SUMMARY.md +479 -0
  31. package/jest.config.js +24 -0
  32. package/package.json +61 -0
  33. package/scripts/background_script_2025-09-29T20-19-35-101Z.js +23 -0
  34. package/scripts/link_ui_policy_actions_2025-09-29T20-17-15-218Z.js +90 -0
  35. package/scripts/set_update_set_Integration_Governance_Framework_2025-09-29T19-47-06-790Z.js +30 -0
  36. package/scripts/set_update_set_Integration_Governance_Framework_2025-09-29T19-59-33-152Z.js +30 -0
  37. package/scripts/set_update_set_current_2025-09-29T20-16-59-675Z.js +24 -0
  38. package/scripts/test_sys_dictionary_403.js +85 -0
  39. package/setup/setup-report.json +5313 -0
  40. package/src/config/comprehensive-table-definitions.json +2575 -0
  41. package/src/config/instance-config.json +4693 -0
  42. package/src/config/prompts.md +59 -0
  43. package/src/config/table-definitions.json +4681 -0
  44. package/src/config-manager.js +146 -0
  45. package/src/mcp-server-consolidated.js +2894 -0
  46. package/src/natural-language.js +472 -0
  47. package/src/resources.js +326 -0
  48. package/src/script-sync.js +428 -0
  49. package/src/server.js +125 -0
  50. package/src/servicenow-client.js +1625 -0
  51. package/src/stdio-server.js +52 -0
  52. package/start-mcp.sh +7 -0
@@ -0,0 +1,1021 @@
1
+ # Flow Designer Best Practices Guide
2
+
3
+ **Version:** 1.0
4
+ **Date:** 2025-10-06
5
+ **Audience:** Developers using ServiceNow MCP Server
6
+
7
+ ---
8
+
9
+ ## Overview
10
+
11
+ Flow Designer is ServiceNow's no-code/low-code automation platform. While powerful through the UI, flow creation **cannot be fully automated** via REST API. This guide provides best practices for working with Flow Designer in an MCP-enabled environment.
12
+
13
+ ---
14
+
15
+ ## Table of Contents
16
+
17
+ 1. [When to Use Flow Designer](#when-to-use-flow-designer)
18
+ 2. [Flow Designer vs Workflow](#flow-designer-vs-workflow)
19
+ 3. [Creating Flows](#creating-flows)
20
+ 4. [Executing Flows](#executing-flows)
21
+ 5. [Flow Templates](#flow-templates)
22
+ 6. [Deployment Strategy](#deployment-strategy)
23
+ 7. [Testing Flows](#testing-flows)
24
+ 8. [Best Practices](#best-practices)
25
+
26
+ ---
27
+
28
+ ## When to Use Flow Designer
29
+
30
+ ### Use Flow Designer For:
31
+
32
+ ✅ **Complex Business Logic**
33
+ - Multi-step approval processes
34
+ - Conditional branching with multiple paths
35
+ - Integration with external systems
36
+ - Data transformation and enrichment
37
+
38
+ ✅ **No-Code/Low-Code Requirements**
39
+ - Business analysts creating automation
40
+ - Rapid prototyping without scripting
41
+ - Visual process documentation
42
+
43
+ ✅ **Modern ServiceNow Features**
44
+ - Integration Hub spokes
45
+ - Flow Designer-specific actions
46
+ - REST API callouts
47
+ - Natural language processing
48
+
49
+ ---
50
+
51
+ ### Use Workflows Instead For:
52
+
53
+ ⚡ **Simple Linear Processes**
54
+ - Basic approval chains
55
+ - Sequential notifications
56
+ - Simple data updates
57
+
58
+ ⚡ **Programmatic Creation**
59
+ - Automated workflow generation
60
+ - Template-based workflows
61
+ - MCP-driven automation
62
+
63
+ **See:** `docs/research/WORKFLOW_VS_FLOW_DESIGNER.md` for detailed comparison
64
+
65
+ ---
66
+
67
+ ## Flow Designer vs Workflow
68
+
69
+ | Feature | Flow Designer | Workflow |
70
+ |---------|--------------|----------|
71
+ | **Creation** | ❌ UI only | ✅ Programmatic via MCP |
72
+ | **Execution** | ✅ FlowAPI | ✅ Workflow API |
73
+ | **Visual Design** | ✅ Modern UI | ⚠️ Legacy UI |
74
+ | **Integration Hub** | ✅ Native support | ❌ Limited |
75
+ | **No-Code** | ✅ Excellent | ⚠️ Basic |
76
+ | **Performance** | ✅ Fast | ✅ Fast |
77
+ | **MCP Automation** | ⚠️ Execution only | ✅ Full automation |
78
+
79
+ **Recommendation:** Use Flow Designer for complex user-facing automation, use Workflows for programmatic automation.
80
+
81
+ ---
82
+
83
+ ## Creating Flows
84
+
85
+ ### Manual Creation (Required)
86
+
87
+ **Steps:**
88
+ 1. Navigate to **Flow Designer** in ServiceNow
89
+ 2. Click **New** → **Flow**
90
+ 3. Define flow properties:
91
+ - **Name:** Descriptive name (e.g., "Auto-Assign High Priority Incidents")
92
+ - **Application:** Choose application scope
93
+ - **Description:** Document purpose and behavior
94
+ 4. Select **Trigger:**
95
+ - **Record Created/Updated:** React to table changes
96
+ - **Scheduled:** Run at intervals
97
+ - **Application Event:** React to custom events
98
+ - **REST API:** Enable REST API execution (MCP-friendly!)
99
+ 5. Add **Actions:**
100
+ - **Create Record**
101
+ - **Update Record**
102
+ - **Send Notification**
103
+ - **Script Step** (for custom logic)
104
+ - **Integration Hub Actions** (external APIs)
105
+ 6. Add **Flow Logic:**
106
+ - **If/Else** conditions
107
+ - **Switch** (multiple branches)
108
+ - **Wait** (delays)
109
+ - **Loop** (iterate over records)
110
+ 7. Test flow with **Test** button
111
+ 8. **Activate** flow when ready
112
+
113
+ ---
114
+
115
+ ### REST API Trigger (MCP-Friendly)
116
+
117
+ For flows that need to be executed via MCP, use **REST API trigger**:
118
+
119
+ **Configuration:**
120
+ ```
121
+ 1. Flow Designer → New Flow
122
+ 2. Trigger: REST API
123
+ 3. Define Inputs:
124
+ - incident_number (String)
125
+ - priority (Integer)
126
+ - category (String)
127
+ 4. Define Outputs:
128
+ - result (String)
129
+ - sys_id (String)
130
+ - error_message (String)
131
+ 5. Build flow logic
132
+ 6. Activate flow
133
+ ```
134
+
135
+ **Execution via MCP:**
136
+ ```javascript
137
+ // Execute REST-triggered flow
138
+ const result = await SN-Execute-Background-Script({
139
+ script: `
140
+ var inputs = {
141
+ incident_number: 'INC0012345',
142
+ priority: 1,
143
+ category: 'hardware'
144
+ };
145
+ var outputs = sn_fd.FlowAPI.executeFlow('your_flow_sys_id', inputs);
146
+ gs.print(JSON.stringify(outputs));
147
+ `,
148
+ description: "Execute auto-assign flow"
149
+ });
150
+ ```
151
+
152
+ **Why This Works:**
153
+ - ✅ Flow created once in UI (manual)
154
+ - ✅ Flow executed programmatically via MCP (automated)
155
+ - ✅ Inputs/outputs clearly defined
156
+ - ✅ Testable and reusable
157
+
158
+ ---
159
+
160
+ ## Executing Flows
161
+
162
+ ### Method 1: FlowAPI (Server-Side)
163
+
164
+ **Use Case:** Execute flows from background scripts, business rules, or scheduled jobs
165
+
166
+ **Implementation:**
167
+ ```javascript
168
+ // Background script via MCP
169
+ await SN-Execute-Background-Script({
170
+ script: `
171
+ // Define inputs
172
+ var inputs = {
173
+ incident_sys_id: 'abc123...',
174
+ assignment_group: 'IT Support'
175
+ };
176
+
177
+ // Execute flow
178
+ var outputs = sn_fd.FlowAPI.executeFlow('flow_sys_id_here', inputs);
179
+
180
+ // Log results
181
+ gs.info('Flow executed: ' + JSON.stringify(outputs));
182
+ `,
183
+ description: "Execute incident assignment flow"
184
+ });
185
+ ```
186
+
187
+ **Get Flow sys_id:**
188
+ ```javascript
189
+ // Query sys_hub_flow table
190
+ await SN-Query-Table({
191
+ table_name: 'sys_hub_flow',
192
+ query: 'name=Auto-Assign Incidents',
193
+ fields: 'sys_id,name,description'
194
+ });
195
+ ```
196
+
197
+ ---
198
+
199
+ ### Method 2: REST API Trigger
200
+
201
+ **Use Case:** Execute flows from external systems or MCP
202
+
203
+ **Prerequisites:**
204
+ - Flow must have **REST API trigger**
205
+ - Flow must be **activated**
206
+
207
+ **Endpoint:**
208
+ ```
209
+ POST /api/now/processflow/flow/{flow_sys_id}
210
+ ```
211
+
212
+ **Request:**
213
+ ```json
214
+ {
215
+ "inputs": {
216
+ "incident_number": "INC0012345",
217
+ "priority": 1
218
+ }
219
+ }
220
+ ```
221
+
222
+ **Response:**
223
+ ```json
224
+ {
225
+ "result": {
226
+ "outputs": {
227
+ "result": "success",
228
+ "assigned_to": "John Smith",
229
+ "sys_id": "abc123..."
230
+ },
231
+ "status": "completed"
232
+ }
233
+ }
234
+ ```
235
+
236
+ **MCP Implementation:**
237
+ ```javascript
238
+ // NOTE: Not yet implemented in MCP server
239
+ // Future tool: SN-Execute-Flow
240
+ await SN-Execute-Flow({
241
+ flow_sys_id: 'abc123...',
242
+ inputs: {
243
+ incident_number: 'INC0012345',
244
+ priority: 1
245
+ }
246
+ });
247
+ ```
248
+
249
+ ---
250
+
251
+ ### Method 3: Subflow Execution
252
+
253
+ **Use Case:** Execute reusable subflows from parent flows or scripts
254
+
255
+ **Subflow Design:**
256
+ - No trigger (executed programmatically)
257
+ - Well-defined inputs and outputs
258
+ - Reusable logic
259
+
260
+ **Execution:**
261
+ ```javascript
262
+ await SN-Execute-Background-Script({
263
+ script: `
264
+ var inputs = { table: 'incident', sys_id: 'abc123...' };
265
+ var outputs = sn_fd.FlowAPI.executeSubflow('subflow_sys_id', inputs);
266
+ gs.print('Subflow result: ' + outputs.result);
267
+ `
268
+ });
269
+ ```
270
+
271
+ ---
272
+
273
+ ## Flow Templates
274
+
275
+ ### Common Flow Patterns
276
+
277
+ ServiceNow MCP Server provides flow templates in `/templates/flows/`:
278
+
279
+ #### 1. Auto-Assignment Flow
280
+
281
+ **Purpose:** Automatically assign records based on criteria
282
+
283
+ **Use Case:**
284
+ - Assign incidents to groups based on category
285
+ - Assign changes to approval groups
286
+ - Round-robin assignment
287
+
288
+ **Template:** `templates/flows/auto-assign-incident.xml`
289
+
290
+ **Configuration:**
291
+ 1. Import template via update set
292
+ 2. Customize assignment rules in flow
293
+ 3. Activate flow
294
+
295
+ ---
296
+
297
+ #### 2. Notification Flow
298
+
299
+ **Purpose:** Send notifications on record events
300
+
301
+ **Use Case:**
302
+ - Email on high-priority incident creation
303
+ - Slack notification on critical alerts
304
+ - Teams notification on approval needed
305
+
306
+ **Template:** `templates/flows/notification-on-create.xml`
307
+
308
+ **Configuration:**
309
+ 1. Import template
310
+ 2. Configure notification recipients
311
+ 3. Customize message template
312
+ 4. Activate flow
313
+
314
+ ---
315
+
316
+ #### 3. Multi-Stage Approval Flow
317
+
318
+ **Purpose:** Complex approval workflows with multiple stages
319
+
320
+ **Use Case:**
321
+ - Change approval (CAB → Manager → Director)
322
+ - Purchase requisition approval
323
+ - Access request approval
324
+
325
+ **Template:** `templates/flows/change-approval.xml`
326
+
327
+ **Configuration:**
328
+ 1. Import template
329
+ 2. Define approval stages
330
+ 3. Configure approval criteria
331
+ 4. Set timeout/escalation rules
332
+ 5. Activate flow
333
+
334
+ ---
335
+
336
+ #### 4. SLA Escalation Flow
337
+
338
+ **Purpose:** Escalate records when SLA breaches
339
+
340
+ **Use Case:**
341
+ - Escalate overdue incidents
342
+ - Notify management on SLA breach
343
+ - Auto-prioritize at-risk tickets
344
+
345
+ **Template:** `templates/flows/sla-escalation.xml`
346
+
347
+ **Configuration:**
348
+ 1. Import template
349
+ 2. Define SLA thresholds
350
+ 3. Configure escalation actions
351
+ 4. Set escalation recipients
352
+ 5. Activate flow
353
+
354
+ ---
355
+
356
+ ## Deployment Strategy
357
+
358
+ ### Development Workflow
359
+
360
+ ```
361
+ ┌─────────────────────────────────────────────────┐
362
+ │ 1. CREATE FLOW IN DEV │
363
+ │ • Flow Designer UI │
364
+ │ • Test with sample data │
365
+ │ • Document inputs/outputs │
366
+ └─────────────────────────────────────────────────┘
367
+
368
+ ┌─────────────────────────────────────────────────┐
369
+ │ 2. CAPTURE IN UPDATE SET │
370
+ │ • SN-Set-Update-Set via MCP │
371
+ │ • Flow automatically captured │
372
+ │ • Verify with SN-Inspect-Update-Set │
373
+ └─────────────────────────────────────────────────┘
374
+
375
+ ┌─────────────────────────────────────────────────┐
376
+ │ 3. EXPORT UPDATE SET │
377
+ │ • Navigate to Update Sets │
378
+ │ • Mark as Complete │
379
+ │ • Export to XML │
380
+ │ • Store in version control │
381
+ └─────────────────────────────────────────────────┘
382
+
383
+ ┌─────────────────────────────────────────────────┐
384
+ │ 4. IMPORT TO TEST │
385
+ │ • Navigate to Retrieved Update Sets │
386
+ │ • Import XML │
387
+ │ • Preview │
388
+ │ • Commit │
389
+ └─────────────────────────────────────────────────┘
390
+
391
+ ┌─────────────────────────────────────────────────┐
392
+ │ 5. TEST IN TEST ENVIRONMENT │
393
+ │ • Execute via FlowAPI │
394
+ │ • Verify outputs │
395
+ │ • Check error handling │
396
+ │ • Performance test │
397
+ └─────────────────────────────────────────────────┘
398
+
399
+ ┌─────────────────────────────────────────────────┐
400
+ │ 6. PROMOTE TO PRODUCTION │
401
+ │ • Import update set to PROD │
402
+ │ • Preview and commit │
403
+ │ • Activate flow │
404
+ │ • Monitor execution │
405
+ └─────────────────────────────────────────────────┘
406
+ ```
407
+
408
+ ---
409
+
410
+ ### MCP-Assisted Deployment
411
+
412
+ **Automated Steps (via MCP):**
413
+
414
+ ```javascript
415
+ // 1. Set update set in DEV
416
+ await SN-Set-Update-Set({
417
+ update_set_sys_id: 'dev_update_set_id',
418
+ instance: 'dev'
419
+ });
420
+
421
+ // 2. Create flow manually in UI (cannot be automated)
422
+ // ... manual work in Flow Designer UI ...
423
+
424
+ // 3. Verify flow captured in update set
425
+ const updateSetContents = await SN-Inspect-Update-Set({
426
+ update_set: 'dev_update_set_id',
427
+ show_components: true,
428
+ instance: 'dev'
429
+ });
430
+
431
+ // 4. Export update set (manual: UI → Export XML)
432
+
433
+ // 5. Import to TEST (manual: Retrieved Update Sets → Import)
434
+
435
+ // 6. Verify flow imported
436
+ const testFlow = await SN-Query-Table({
437
+ table_name: 'sys_hub_flow',
438
+ query: 'name=My Flow Name',
439
+ instance: 'test'
440
+ });
441
+
442
+ // 7. Test flow execution
443
+ await SN-Execute-Background-Script({
444
+ script: `
445
+ var inputs = { test: 'data' };
446
+ var outputs = sn_fd.FlowAPI.executeFlow('${testFlow.sys_id}', inputs);
447
+ gs.info('Test result: ' + JSON.stringify(outputs));
448
+ `,
449
+ instance: 'test'
450
+ });
451
+
452
+ // 8. Promote to PROD (repeat import steps)
453
+ ```
454
+
455
+ ---
456
+
457
+ ## Testing Flows
458
+
459
+ ### Test Strategy
460
+
461
+ #### Unit Testing (Flow Designer)
462
+
463
+ **Built-in Test Runner:**
464
+ 1. Open flow in Flow Designer
465
+ 2. Click **Test** button
466
+ 3. Provide test inputs
467
+ 4. Verify outputs
468
+ 5. Check execution log
469
+
470
+ **Best Practices:**
471
+ - Test happy path
472
+ - Test error conditions
473
+ - Test edge cases (null values, empty strings)
474
+ - Test with real production-like data
475
+
476
+ ---
477
+
478
+ #### Integration Testing (ATF)
479
+
480
+ **Automated Test Framework (ATF):**
481
+
482
+ While ATF test creation is UI-only, you can execute tests via MCP:
483
+
484
+ ```javascript
485
+ // Execute ATF test suite
486
+ await SN-Execute-Background-Script({
487
+ script: `
488
+ var testRunner = new sn_atf.TestRunner();
489
+ var result = testRunner.runTest('test_sys_id_here');
490
+ gs.info('Test result: ' + result.getStatus());
491
+ `
492
+ });
493
+ ```
494
+
495
+ **ATF Test Coverage:**
496
+ - Flow triggers correctly
497
+ - Inputs processed correctly
498
+ - Outputs match expectations
499
+ - Error handling works
500
+ - Performance meets SLAs
501
+
502
+ ---
503
+
504
+ #### Smoke Testing (Production)
505
+
506
+ **Post-Deployment Verification:**
507
+
508
+ ```javascript
509
+ // Smoke test in production
510
+ await SN-Execute-Background-Script({
511
+ script: `
512
+ // Execute flow with known-good data
513
+ var inputs = { test_mode: true, incident_number: 'INC0000001' };
514
+ var outputs = sn_fd.FlowAPI.executeFlow('flow_sys_id', inputs);
515
+
516
+ // Verify expected output
517
+ if (outputs.result === 'success') {
518
+ gs.info('✅ Smoke test passed');
519
+ } else {
520
+ gs.error('❌ Smoke test failed: ' + outputs.error);
521
+ }
522
+ `,
523
+ instance: 'prod'
524
+ });
525
+ ```
526
+
527
+ ---
528
+
529
+ ## Best Practices
530
+
531
+ ### Design Principles
532
+
533
+ #### 1. Single Responsibility
534
+
535
+ **Bad:**
536
+ ```
537
+ Flow: "Process Incident"
538
+ ├── Assign incident
539
+ ├── Send notification
540
+ ├── Create change request
541
+ ├── Update CMDB
542
+ └── Generate report
543
+ ```
544
+
545
+ **Good:**
546
+ ```
547
+ Flow: "Auto-Assign Incident"
548
+ └── Assign incident based on category
549
+
550
+ Flow: "Notify on Assignment"
551
+ └── Send notification to assignee
552
+
553
+ Flow: "Create Related Change"
554
+ └── Create change request from incident
555
+ ```
556
+
557
+ **Why:** Smaller flows are easier to test, debug, and reuse
558
+
559
+ ---
560
+
561
+ #### 2. Clear Input/Output Contracts
562
+
563
+ **Bad:**
564
+ ```javascript
565
+ // Ambiguous inputs
566
+ inputs: {
567
+ data: "some data",
568
+ flag: true,
569
+ stuff: { ... }
570
+ }
571
+ ```
572
+
573
+ **Good:**
574
+ ```javascript
575
+ // Well-defined inputs
576
+ inputs: {
577
+ incident_sys_id: "abc123...", // Required, sys_id format
578
+ assignment_group: "IT Support", // Required, group name
579
+ priority_override: 2, // Optional, 1-5
580
+ skip_notification: false // Optional, boolean
581
+ }
582
+
583
+ outputs: {
584
+ result: "success", // "success" or "error"
585
+ assigned_to: "john.smith", // User ID
586
+ sys_id: "def456...", // Updated record sys_id
587
+ error_message: null // Error details if result="error"
588
+ }
589
+ ```
590
+
591
+ **Why:** Clear contracts make flows easier to integrate and debug
592
+
593
+ ---
594
+
595
+ #### 3. Comprehensive Error Handling
596
+
597
+ **Pattern:**
598
+ ```
599
+ Flow Start
600
+
601
+ Try: Execute Logic
602
+
603
+ Success? → Set output: result="success"
604
+
605
+ Error? → Catch Error
606
+
607
+ Log Error
608
+
609
+ Set output: result="error", error_message="..."
610
+
611
+ Flow End
612
+ ```
613
+
614
+ **Implementation:**
615
+ - Use **If** condition to check for errors
616
+ - Set output variables for both success and error paths
617
+ - Log errors to system log
618
+ - Return meaningful error messages
619
+ - Don't fail silently
620
+
621
+ ---
622
+
623
+ #### 4. Idempotency
624
+
625
+ **Principle:** Flow can be safely re-executed without unintended side effects
626
+
627
+ **Example: Assign Incident**
628
+ ```javascript
629
+ // BAD: Always assigns (creates duplicates on retry)
630
+ current.assignment_group = 'IT Support';
631
+ current.update();
632
+
633
+ // GOOD: Only assigns if not already assigned
634
+ if (current.assignment_group.nil()) {
635
+ current.assignment_group = 'IT Support';
636
+ current.update();
637
+ }
638
+ ```
639
+
640
+ **Why:** Flows may be retried on errors, timeouts, or manual re-execution
641
+
642
+ ---
643
+
644
+ #### 5. Performance Optimization
645
+
646
+ **Tips:**
647
+ - ✅ Minimize database queries (use inputs instead of lookups)
648
+ - ✅ Batch operations when possible
649
+ - ✅ Use indexes on queried fields
650
+ - ✅ Avoid loops with large datasets
651
+ - ✅ Set reasonable timeouts
652
+
653
+ **Performance Targets:**
654
+ - Simple flows: <1 second
655
+ - Complex flows: <5 seconds
656
+ - Flows with external APIs: <10 seconds
657
+
658
+ **Monitoring:**
659
+ ```javascript
660
+ // Check flow execution time
661
+ await SN-Query-Table({
662
+ table_name: 'sys_flow_context',
663
+ query: 'flow=abc123...^ORDERBYDESCsys_created_on',
664
+ fields: 'state,duration,sys_created_on',
665
+ limit: 10
666
+ });
667
+ ```
668
+
669
+ ---
670
+
671
+ #### 6. Logging and Observability
672
+
673
+ **Log Important Events:**
674
+ ```javascript
675
+ // In Script Step action
676
+ gs.info('Flow started for incident: ' + inputs.incident_number);
677
+
678
+ // On error
679
+ gs.error('Flow failed: ' + error.message);
680
+
681
+ // On success
682
+ gs.info('Flow completed: assigned to ' + outputs.assigned_to);
683
+ ```
684
+
685
+ **Monitor Flow Execution:**
686
+ ```javascript
687
+ // Query flow execution history
688
+ await SN-Query-Table({
689
+ table_name: 'sys_flow_context',
690
+ query: 'flow.name=My Flow^state=failed',
691
+ fields: 'sys_id,state,error_message,sys_created_on',
692
+ limit: 10
693
+ });
694
+ ```
695
+
696
+ ---
697
+
698
+ #### 7. Version Control
699
+
700
+ **Update Set Management:**
701
+
702
+ ```javascript
703
+ // Create update set for flow development
704
+ const updateSet = await SN-Create-Record({
705
+ table_name: 'sys_update_set',
706
+ data: {
707
+ name: 'Auto-Assign Flow v2.0',
708
+ description: 'Enhanced auto-assignment logic with category-based routing',
709
+ state: 'in progress'
710
+ }
711
+ });
712
+
713
+ // Set as current
714
+ await SN-Set-Update-Set({
715
+ update_set_sys_id: updateSet.sys_id
716
+ });
717
+
718
+ // Make flow changes in UI
719
+
720
+ // Export update set and commit to git
721
+ // Store in: git/update-sets/auto-assign-v2.0.xml
722
+ ```
723
+
724
+ **Git Repository Structure:**
725
+ ```
726
+ /repo
727
+ ├── update-sets/
728
+ │ ├── auto-assign-v1.0.xml
729
+ │ ├── auto-assign-v2.0.xml
730
+ │ └── notification-flow-v1.0.xml
731
+ ├── flow-docs/
732
+ │ ├── auto-assign-flow.md
733
+ │ └── notification-flow.md
734
+ └── test-data/
735
+ ├── auto-assign-test-inputs.json
736
+ └── notification-test-inputs.json
737
+ ```
738
+
739
+ ---
740
+
741
+ ## Common Patterns
742
+
743
+ ### Pattern 1: Conditional Assignment
744
+
745
+ **Use Case:** Assign records to different groups based on criteria
746
+
747
+ **Flow Structure:**
748
+ ```
749
+ Trigger: Incident Created
750
+
751
+ If: category = "hardware"
752
+ → Assign to "Hardware Support"
753
+ Else If: category = "software"
754
+ → Assign to "Software Support"
755
+ Else If: category = "network"
756
+ → Assign to "Network Team"
757
+ Else
758
+ → Assign to "General Support"
759
+ ```
760
+
761
+ **MCP Execution:**
762
+ ```javascript
763
+ await SN-Execute-Background-Script({
764
+ script: `
765
+ var inputs = { incident_sys_id: 'abc123...' };
766
+ var outputs = sn_fd.FlowAPI.executeFlow('conditional_assign_flow_id', inputs);
767
+ gs.info('Assigned to: ' + outputs.assignment_group);
768
+ `
769
+ });
770
+ ```
771
+
772
+ ---
773
+
774
+ ### Pattern 2: Approval Chain
775
+
776
+ **Use Case:** Multi-stage approval process
777
+
778
+ **Flow Structure:**
779
+ ```
780
+ Trigger: Change Request Created
781
+
782
+ Stage 1: Submit for CAB Approval
783
+
784
+ Wait: CAB Approval
785
+
786
+ Approved? → Stage 2: Submit to Manager
787
+
788
+ Wait: Manager Approval
789
+
790
+ Approved? → Stage 3: Submit to Director
791
+
792
+ Wait: Director Approval
793
+
794
+ Approved? → Change to "Approved" state
795
+ Rejected? → Change to "Rejected" state
796
+ ```
797
+
798
+ ---
799
+
800
+ ### Pattern 3: Integration with External System
801
+
802
+ **Use Case:** Call external REST API from flow
803
+
804
+ **Flow Structure:**
805
+ ```
806
+ Trigger: Incident Created
807
+
808
+ Action: REST API Call
809
+ URL: https://external-api.com/tickets
810
+ Method: POST
811
+ Body: { incident: current.number }
812
+
813
+ Parse Response
814
+
815
+ Update Incident with External Ticket ID
816
+ ```
817
+
818
+ **Integration Hub:** Use spoke actions for common integrations (Slack, Teams, Jira, etc.)
819
+
820
+ ---
821
+
822
+ ## Troubleshooting
823
+
824
+ ### Common Issues
825
+
826
+ #### Issue 1: Flow Not Triggering
827
+
828
+ **Symptoms:**
829
+ - Flow exists and is active
830
+ - Trigger condition met
831
+ - Flow doesn't execute
832
+
833
+ **Causes:**
834
+ - Flow not activated
835
+ - Trigger condition incorrect
836
+ - Application scope mismatch
837
+ - User lacks permissions
838
+
839
+ **Debug Steps:**
840
+ ```javascript
841
+ // 1. Verify flow is active
842
+ await SN-Get-Record({
843
+ table_name: 'sys_hub_flow',
844
+ sys_id: 'flow_sys_id',
845
+ fields: 'name,active,application'
846
+ });
847
+
848
+ // 2. Check recent executions
849
+ await SN-Query-Table({
850
+ table_name: 'sys_flow_context',
851
+ query: 'flow=flow_sys_id^ORDERBYDESCsys_created_on',
852
+ fields: 'state,error_message,sys_created_on',
853
+ limit: 10
854
+ });
855
+
856
+ // 3. Check system logs
857
+ // Navigate to: System Logs → System Log → All
858
+ // Filter: Source = "Flow Designer"
859
+ ```
860
+
861
+ ---
862
+
863
+ #### Issue 2: Flow Execution Failed
864
+
865
+ **Symptoms:**
866
+ - Flow triggers but fails mid-execution
867
+ - Error message in flow context
868
+
869
+ **Debug:**
870
+ ```javascript
871
+ // Get flow context with error
872
+ await SN-Query-Table({
873
+ table_name: 'sys_flow_context',
874
+ query: 'flow=flow_sys_id^state=failed',
875
+ fields: 'sys_id,state,error_message,stage',
876
+ limit: 1
877
+ });
878
+
879
+ // Get execution details
880
+ await SN-Get-Record({
881
+ table_name: 'sys_flow_context',
882
+ sys_id: 'context_sys_id',
883
+ fields: 'error_message,stage,state,data'
884
+ });
885
+ ```
886
+
887
+ **Common Errors:**
888
+ - Null reference (check input data)
889
+ - Permission error (check user ACLs)
890
+ - Timeout (optimize flow performance)
891
+ - API limit exceeded (add retry logic)
892
+
893
+ ---
894
+
895
+ #### Issue 3: Slow Flow Performance
896
+
897
+ **Symptoms:**
898
+ - Flow takes >10 seconds
899
+ - Timeouts in production
900
+
901
+ **Optimization:**
902
+ ```javascript
903
+ // Profile flow execution
904
+ await SN-Query-Table({
905
+ table_name: 'sys_flow_context',
906
+ query: 'flow=flow_sys_id^ORDERBYDESCduration',
907
+ fields: 'sys_id,duration,stage',
908
+ limit: 10
909
+ });
910
+
911
+ // Identify slow stages
912
+ // Optimize database queries
913
+ // Reduce external API calls
914
+ // Add caching where possible
915
+ ```
916
+
917
+ ---
918
+
919
+ ## Migration from Workflow
920
+
921
+ ### When to Migrate
922
+
923
+ **Consider Migration When:**
924
+ - ✅ Need modern UI and better user experience
925
+ - ✅ Want to use Integration Hub spokes
926
+ - ✅ Need complex branching logic
927
+ - ✅ Want better error handling
928
+
929
+ **Stay with Workflow When:**
930
+ - ✅ Workflow works well and is stable
931
+ - ✅ Need programmatic creation (MCP automation)
932
+ - ✅ Simple linear processes
933
+ - ✅ Don't have time for migration effort
934
+
935
+ ---
936
+
937
+ ### Migration Process
938
+
939
+ **Steps:**
940
+ 1. Document existing workflow logic
941
+ 2. Create equivalent flow in Flow Designer
942
+ 3. Test flow with production data
943
+ 4. Run both workflow and flow in parallel (monitoring)
944
+ 5. Disable workflow, activate flow
945
+ 6. Monitor for issues
946
+ 7. Remove old workflow when stable
947
+
948
+ **MCP Support:**
949
+ ```javascript
950
+ // Disable old workflow
951
+ await SN-Update-Record({
952
+ table_name: 'wf_workflow',
953
+ sys_id: 'workflow_sys_id',
954
+ data: { active: false }
955
+ });
956
+
957
+ // Activate new flow
958
+ await SN-Update-Record({
959
+ table_name: 'sys_hub_flow',
960
+ sys_id: 'flow_sys_id',
961
+ data: { active: true }
962
+ });
963
+
964
+ // Monitor both
965
+ await SN-Query-Table({
966
+ table_name: 'sys_flow_context',
967
+ query: 'flow=flow_sys_id^sys_created_on>=javascript:gs.daysAgo(1)',
968
+ fields: 'state,sys_created_on'
969
+ });
970
+ ```
971
+
972
+ ---
973
+
974
+ ## Resources
975
+
976
+ **ServiceNow Documentation:**
977
+ - Flow Designer User Guide
978
+ - FlowAPI Reference
979
+ - Integration Hub Documentation
980
+
981
+ **MCP Documentation:**
982
+ - `/docs/API_REFERENCE.md` - MCP tool reference
983
+ - `/docs/research/FLOW_DESIGNER_LIMITATIONS.md` - Technical limitations
984
+ - `/docs/research/WORKFLOW_VS_FLOW_DESIGNER.md` - Comparison guide
985
+ - `/docs/UI_OPERATIONS_ARCHITECTURE.md` - Architecture decisions
986
+
987
+ **Templates:**
988
+ - `/templates/flows/auto-assign-incident.xml`
989
+ - `/templates/flows/notification-on-create.xml`
990
+ - `/templates/flows/change-approval.xml`
991
+ - `/templates/flows/sla-escalation.xml`
992
+
993
+ ---
994
+
995
+ ## Summary
996
+
997
+ **Key Takeaways:**
998
+
999
+ 1. ✅ **Flow Designer creation is UI-only** (cannot be automated via MCP)
1000
+ 2. ✅ **Flow execution is fully automated** via FlowAPI and background scripts
1001
+ 3. ✅ **Use REST API triggers** for MCP-friendly flows
1002
+ 4. ✅ **Update sets handle deployment** across environments
1003
+ 5. ✅ **Templates accelerate development** for common patterns
1004
+ 6. ✅ **FlowAPI enables programmatic execution** from MCP
1005
+
1006
+ **Recommended Workflow:**
1007
+ 1. Create flows manually in UI (one-time effort)
1008
+ 2. Capture in update sets automatically (via MCP)
1009
+ 3. Export and version control update sets
1010
+ 4. Execute flows programmatically via FlowAPI (fully automated)
1011
+ 5. Monitor and optimize flow performance
1012
+
1013
+ **For Questions:**
1014
+ - Check Flow Designer documentation
1015
+ - Review flow templates in `/templates/flows/`
1016
+ - Consult `docs/research/FLOW_DESIGNER_LIMITATIONS.md`
1017
+ - Test in sub-production before deploying to prod
1018
+
1019
+ ---
1020
+
1021
+ **END OF GUIDE**