snow-flow 3.4.11 → 3.4.14

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.
@@ -52,68 +52,214 @@ const propertyCheck = await snow_property_manager({
52
52
 
53
53
  ## Fundamental Rules
54
54
 
55
- ### Rule 1: ES5 JavaScript Only in ServiceNow
55
+ ### Rule 1: 🚨 ES5 JavaScript ONLY in ServiceNow - NO EXCEPTIONS!
56
56
 
57
- ServiceNow uses the Rhino JavaScript engine which supports only ES5. Modern JavaScript syntax will fail.
57
+ **⚠️ CRITICAL WARNING: ServiceNow uses Rhino engine - ES6/ES7/ES8+ WILL FAIL!**
58
58
 
59
- **Never Use:**
60
- - \`const\` or \`let\` - use \`var\`
61
- - Arrow functions \`() => {}\` - use \`function() {}\`
62
- - Template literals \`\` \`\${var}\` \`\` - use string concatenation
63
- - Destructuring \`{a, b} = obj\` - use explicit property access
64
- - \`for...of\` loops - use traditional \`for\` loops
65
- - Default parameters - use \`typeof\` checks
66
- - \`async/await\` - use callbacks or GlideAjax
59
+ ServiceNow's server-side JavaScript runs on Mozilla Rhino which **ONLY supports ES5 (2009)**. Any modern JavaScript syntax will cause **RUNTIME ERRORS**.
67
60
 
68
- **Always Use:**
61
+ **❌ THESE WILL CRASH SERVICENOW (DO NOT USE):**
69
62
  \`\`\`javascript
70
- // ES5 compatible code
71
- var name = 'value';
72
- function processData() {
73
- return 'result';
63
+ // ❌ ES6+ features that BREAK ServiceNow:
64
+ const data = []; // SyntaxError: missing ; after for-loop initializer
65
+ let items = []; // SyntaxError: missing ; after for-loop initializer
66
+ const fn = () => {}; // SyntaxError: syntax error
67
+ var msg = \`Hello \${name}\`; // SyntaxError: syntax error
68
+ for (let item of items){} // SyntaxError: missing ; after for-loop initializer
69
+ var {name, id} = user; // SyntaxError: destructuring declaration not supported
70
+ array.forEach(x => {}); // SyntaxError: syntax error
71
+ array.map(x => x.id); // SyntaxError: syntax error
72
+ function test(param = 'default') {} // SyntaxError: syntax error
73
+ class MyClass {} // SyntaxError: missing ; after for-loop initializer
74
+ \`\`\`
75
+
76
+ **✅ ONLY USE ES5 SYNTAX (THIS WORKS):**
77
+ \`\`\`javascript
78
+ // ✅ ES5 compatible code that WORKS in ServiceNow:
79
+ var data = [];
80
+ var items = [];
81
+ function fn() { return 'result'; }
82
+ var msg = 'Hello ' + name;
83
+ for (var i = 0; i < items.length; i++) {
84
+ var item = items[i];
74
85
  }
75
- var message = 'Hello ' + userName;
76
- for (var i = 0; i < array.length; i++) {
77
- var item = array[i];
86
+ var name = user.name;
87
+ var id = user.id;
88
+ for (var j = 0; j < array.length; j++) {
89
+ // Process array[j]
90
+ }
91
+ function test(param) {
92
+ if (typeof param === 'undefined') param = 'default';
78
93
  }
79
94
  \`\`\`
80
95
 
96
+ **🔥 COMMON MISTAKES THAT BREAK SERVICENOW:**
97
+ 1. **Arrow Functions**: \`() => {}\` → Use \`function() {}\`
98
+ 2. **Template Literals**: \`\` \`\${var}\` \`\` → Use \`'text ' + var\`
99
+ 3. **Let/Const**: \`let x\` → Use \`var x\`
100
+ 4. **Destructuring**: \`{a, b} = obj\` → Use \`obj.a\`, \`obj.b\`
101
+ 5. **For...of**: \`for (x of arr)\` → Use \`for (var i=0; i<arr.length; i++)\`
102
+ 6. **Default Parameters**: \`fn(x='default')\` → Use \`typeof x === 'undefined'\`
103
+ 7. **Array Methods with Arrows**: \`.map(x => x)\` → Use \`.map(function(x) { return x; })\`
104
+
81
105
  ### Rule 2: Background Scripts for Verification Only (Not Widget Updates!)
82
106
 
83
107
  **CRITICAL DISTINCTION:**
84
- - ✅ Use background scripts for TESTING and VERIFICATION
108
+ - ✅ Use background scripts for TESTING and VERIFICATION
85
109
  - ❌ Do NOT use background scripts to UPDATE widget fields
86
110
  - ✅ Use \`snow_update\` to directly modify widget records
87
111
  - ❌ Do NOT try to import server scripts into client scripts via background scripts
88
112
 
113
+ **🚨 ES5 ENFORCEMENT FOR BACKGROUND SCRIPTS:**
114
+ Background scripts run on ServiceNow's server-side Rhino engine. **EVERY background script MUST be ES5-only or it will fail.**
115
+
116
+ **Quick ES5 Validation Checklist:**
117
+ - [ ] No \`const\` or \`let\` (only \`var\`)
118
+ - [ ] No arrow functions \`() => {}\` (only \`function() {}\`)
119
+ - [ ] No template literals \`\` \`\${var}\` \`\` (only string concatenation)
120
+ - [ ] No destructuring \`{a, b} = obj\` (only explicit \`obj.a\`)
121
+ - [ ] No \`for...of\` loops (only traditional \`for\` loops)
122
+ - [ ] No default parameters (use \`typeof\` checks)
123
+ - [ ] No modern array methods with arrows (use traditional functions)
124
+
89
125
  Background scripts are excellent for verification and debugging, but widget updates must go through proper MCP tools.
90
126
 
91
127
  **NEW: Auto-Confirm Mode for Background Scripts (v3.4.10+)**
92
128
  You can now skip the human-in-the-loop confirmation for trusted scripts:
93
129
 
94
130
  \`\`\`javascript
95
- // Standard mode - requires user confirmation
131
+ // Standard mode - requires user confirmation (ES5 ONLY!)
96
132
  snow_execute_background_script({
97
- script: "var gr = new GlideRecord('incident'); gr.query();",
133
+ script: "var gr = new GlideRecord('incident'); gr.query();", // ✅ ES5 syntax
98
134
  description: "Query incidents",
99
135
  allowDataModification: false
100
136
  });
101
137
 
102
138
  // Auto-confirm mode - executes immediately ⚠️ USE WITH CAUTION!
103
139
  snow_execute_background_script({
104
- script: "var gr = new GlideRecord('incident'); gr.query();",
140
+ script: "var gr = new GlideRecord('incident'); gr.query();", // ✅ ES5 syntax
105
141
  description: "Query incidents",
106
142
  allowDataModification: false,
107
143
  autoConfirm: true // ⚠️ Bypasses user confirmation!
108
144
  });
145
+
146
+ // ❌ WRONG - This will FAIL in ServiceNow:
147
+ // script: "const gr = new GlideRecord('incident'); gr.query();", // SyntaxError!
148
+ // script: "incidents.forEach(i => console.log(i.number));", // SyntaxError!
109
149
  \`\`\`
110
150
 
151
+ **🚨 ES5 Validation Required:**
152
+ Before using any background script tool, validate your script is ES5-only:
153
+ - No \`const\`/\`let\` (use \`var\`)
154
+ - No arrow functions (use \`function()\`)
155
+ - No template literals (use string concatenation)
156
+ - No destructuring (use explicit property access)
157
+
111
158
  **⚠️ Security Warning:**
112
159
  - Only use \`autoConfirm: true\` for verified, safe scripts
113
160
  - High-risk operations will still be logged
114
161
  - All auto-executions are tracked with audit IDs
115
162
  - Default behavior (without autoConfirm) remains unchanged
116
163
 
164
+ ## 🚨 CRITICAL: Common ES5 Mistakes That Break ServiceNow
165
+
166
+ ServiceNow developers frequently use modern JavaScript that fails on the Rhino engine. Here are the most common mistakes:
167
+
168
+ ### 🔥 Top ES5 Violations (Fix These Immediately!)
169
+
170
+ **1. Arrow Functions with Array Methods**
171
+ \`\`\`javascript
172
+ // ❌ BREAKS ServiceNow:
173
+ var activeIncidents = incidents.filter(inc => inc.active);
174
+ var numbers = activeIncidents.map(inc => inc.number);
175
+
176
+ // ✅ WORKS in ServiceNow:
177
+ var activeIncidents = [];
178
+ for (var i = 0; i < incidents.length; i++) {
179
+ if (incidents[i].active) {
180
+ activeIncidents.push(incidents[i]);
181
+ }
182
+ }
183
+ var numbers = [];
184
+ for (var j = 0; j < activeIncidents.length; j++) {
185
+ numbers.push(activeIncidents[j].number);
186
+ }
187
+ \`\`\`
188
+
189
+ **2. Template Literals for String Building**
190
+ \`\`\`javascript
191
+ // ❌ BREAKS ServiceNow:
192
+ var message = \`Incident \${incident.number} assigned to \${user.name}\`;
193
+
194
+ // ✅ WORKS in ServiceNow:
195
+ var message = 'Incident ' + incident.number + ' assigned to ' + user.name;
196
+ \`\`\`
197
+
198
+ **3. Const/Let Variable Declarations**
199
+ \`\`\`javascript
200
+ // ❌ BREAKS ServiceNow:
201
+ const MAX_RETRIES = 3;
202
+ let currentUser = gs.getUser();
203
+
204
+ // ✅ WORKS in ServiceNow:
205
+ var MAX_RETRIES = 3;
206
+ var currentUser = gs.getUser();
207
+ \`\`\`
208
+
209
+ **4. Object Destructuring**
210
+ \`\`\`javascript
211
+ // ❌ BREAKS ServiceNow:
212
+ var {name, email, department} = user;
213
+ var {sys_id: id, short_description: desc} = incident;
214
+
215
+ // ✅ WORKS in ServiceNow:
216
+ var name = user.name;
217
+ var email = user.email;
218
+ var department = user.department;
219
+ var id = incident.sys_id;
220
+ var desc = incident.short_description;
221
+ \`\`\`
222
+
223
+ **5. For...of Loops**
224
+ \`\`\`javascript
225
+ // ❌ BREAKS ServiceNow:
226
+ for (let incident of incidents) {
227
+ gs.info('Processing: ' + incident.number);
228
+ }
229
+
230
+ // ✅ WORKS in ServiceNow:
231
+ for (var i = 0; i < incidents.length; i++) {
232
+ gs.info('Processing: ' + incidents[i].number);
233
+ }
234
+ \`\`\`
235
+
236
+ **6. Default Function Parameters**
237
+ \`\`\`javascript
238
+ // ❌ BREAKS ServiceNow:
239
+ function processIncident(incident, priority = 3, assignee = 'unassigned') {
240
+ // Process incident
241
+ }
242
+
243
+ // ✅ WORKS in ServiceNow:
244
+ function processIncident(incident, priority, assignee) {
245
+ if (typeof priority === 'undefined') priority = 3;
246
+ if (typeof assignee === 'undefined') assignee = 'unassigned';
247
+ // Process incident
248
+ }
249
+ \`\`\`
250
+
251
+ ### 🎯 Quick ES5 Conversion Guide
252
+ | Modern (ES6+) | ES5 Equivalent |
253
+ |---------------|----------------|
254
+ | \`const x = 5;\` | \`var x = 5;\` |
255
+ | \`let items = [];\` | \`var items = [];\` |
256
+ | \`() => {}\` | \`function() {}\` |
257
+ | \`\` \`Hello \${name}\` \`\` | \`'Hello ' + name\` |
258
+ | \`{a, b} = obj\` | \`var a = obj.a; var b = obj.b;\` |
259
+ | \`for (item of items)\` | \`for (var i = 0; i < items.length; i++)\` |
260
+ | \`func(x = 'default')\` | \`if (typeof x === 'undefined') x = 'default';\` |
261
+ | \`arr.map(x => x.id)\` | \`arr.map(function(x) { return x.id; })\` |
262
+
117
263
  \`\`\`javascript
118
264
  // Universal verification pattern
119
265
  const verify = await snow_execute_script_with_output({
@@ -314,18 +460,23 @@ Snow-Flow includes 16+ specialized MCP servers with over 200 tools for comprehen
314
460
  ### 3. ServiceNow Automation Server
315
461
  **Purpose:** Script execution and automation
316
462
 
463
+ **🚨 CRITICAL: ALL SCRIPTS MUST BE ES5 ONLY!**
464
+ ServiceNow runs on Rhino engine - ES6+ syntax will cause SyntaxError and script failure.
465
+
317
466
  **Key Tools:**
318
- - \`snow_execute_background_script\` - Execute background scripts (with optional autoConfirm)
467
+ - \`snow_execute_background_script\` - Execute background scripts (**ES5 ONLY!** with optional autoConfirm)
319
468
  - \`snow_confirm_script_execution\` - Confirm script execution after user approval
320
- - \`snow_execute_script_with_output\` - Execute scripts with output capture
469
+ - \`snow_execute_script_with_output\` - Execute scripts with output capture (**ES5 ONLY!**)
321
470
  - \`snow_get_script_output\` - Retrieve script execution history
322
- - \`snow_execute_script_sync\` - Synchronous script execution
471
+ - \`snow_execute_script_sync\` - Synchronous script execution (**ES5 ONLY!**)
323
472
  - \`snow_get_logs\` - Access system logs
324
473
  - \`snow_test_rest_connection\` - Test REST integrations
325
- - \`snow_trace_execution\` - Trace script execution
474
+ - \`snow_trace_execution\` - Trace script execution (**ES5 ONLY!**)
326
475
  - \`snow_schedule_job\` - Create scheduled jobs
327
476
  - \`snow_create_event\` - Trigger system events
328
477
 
478
+ **Remember:** Use \`var\`, \`function(){}\`, string concatenation, traditional for loops only!
479
+
329
480
  **Features:**
330
481
  - Full output capture (gs.print/info/warn/error)
331
482
  - Execution history tracking
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "snow-flow",
3
- "version": "3.4.11",
3
+ "version": "3.4.14",
4
4
  "description": "ServiceNow development framework with MCP server integration. Executes background scripts using ES5 JavaScript only (ServiceNow Rhino engine requirement). Provides 12 MCP servers for ServiceNow operations including widget deployment with coherence validation, table operations, script execution, and system property management.",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",