snow-flow 10.0.1-dev.410 → 10.0.1-dev.412
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.
package/package.json
CHANGED
|
@@ -124,9 +124,11 @@ async function createFlowViaScheduledJob(
|
|
|
124
124
|
" } catch(t1e) { r.steps.tier1 = { success: false, error: t1e.getMessage ? t1e.getMessage() : t1e + '' }; }",
|
|
125
125
|
"",
|
|
126
126
|
// ── TIER 2: GlideRecord ──
|
|
127
|
-
//
|
|
128
|
-
//
|
|
129
|
-
//
|
|
127
|
+
// Reference flow analysis shows:
|
|
128
|
+
// - flow_definition on flow record = null (working flows don't have it)
|
|
129
|
+
// - latest_snapshot = 32-char sys_id (reference, NOT JSON!)
|
|
130
|
+
// - latest_version = null (normal on this instance)
|
|
131
|
+
// So: DON'T set flow_definition on flow, set latest_snapshot = version sys_id.
|
|
130
132
|
" if (!flowSysId) {",
|
|
131
133
|
" try {",
|
|
132
134
|
" var f = new GlideRecord('sys_hub_flow');",
|
|
@@ -136,9 +138,10 @@ async function createFlowViaScheduledJob(
|
|
|
136
138
|
" f.setValue('run_as', runAs); f.setValue('active', false);",
|
|
137
139
|
" f.setValue('status', 'draft'); f.setValue('validated', true);",
|
|
138
140
|
" f.setValue('type', isSubflow ? 'subflow' : 'flow');",
|
|
139
|
-
|
|
141
|
+
// Do NOT set flow_definition (null on working flows)
|
|
142
|
+
// Do NOT set latest_snapshot yet (set after version insert — it's a sys_id ref)
|
|
140
143
|
" flowSysId = f.insert();",
|
|
141
|
-
" r.steps.flow_insert = { success: !!flowSysId, sys_id: flowSysId + ''
|
|
144
|
+
" r.steps.flow_insert = { success: !!flowSysId, sys_id: flowSysId + '' };",
|
|
142
145
|
" if (flowSysId) {",
|
|
143
146
|
" var v = new GlideRecord('sys_hub_flow_version');",
|
|
144
147
|
" v.initialize();",
|
|
@@ -146,30 +149,20 @@ async function createFlowViaScheduledJob(
|
|
|
146
149
|
" v.setValue('version', '1.0'); v.setValue('state', 'draft');",
|
|
147
150
|
" v.setValue('active', true); v.setValue('compile_state', 'draft');",
|
|
148
151
|
" v.setValue('is_current', true);",
|
|
149
|
-
" v.setValue('internal_name', intName + '_v1_0');",
|
|
150
152
|
" if (flowDefStr) { v.setValue('flow_definition', flowDefStr); }",
|
|
151
153
|
" verSysId = v.insert();",
|
|
152
|
-
" r.steps.version_insert = { success: !!verSysId, sys_id: verSysId + ''
|
|
154
|
+
" r.steps.version_insert = { success: !!verSysId, sys_id: verSysId + '' };",
|
|
153
155
|
"",
|
|
154
|
-
//
|
|
156
|
+
// Set latest_snapshot on flow record to version sys_id (reference field, not JSON)
|
|
155
157
|
" if (verSysId) {",
|
|
156
158
|
" try {",
|
|
157
159
|
" var flowUpd = new GlideRecord('sys_hub_flow');",
|
|
158
|
-
" flowUpd.setWorkflow(false);",
|
|
159
|
-
" flowUpd.autoSysFields(false);",
|
|
160
160
|
" if (flowUpd.get(flowSysId)) {",
|
|
161
|
-
" flowUpd.setValue('
|
|
161
|
+
" flowUpd.setValue('latest_snapshot', verSysId);",
|
|
162
162
|
" flowUpd.update();",
|
|
163
|
-
" r.steps.
|
|
163
|
+
" r.steps.latest_snapshot_set = verSysId + '';",
|
|
164
164
|
" }",
|
|
165
|
-
" } catch(
|
|
166
|
-
// Verify latest_version was set
|
|
167
|
-
" var lvCheck = new GlideRecord('sys_hub_flow');",
|
|
168
|
-
" if (lvCheck.get(flowSysId)) {",
|
|
169
|
-
" var lvVal = lvCheck.getValue('latest_version');",
|
|
170
|
-
" r.steps.latest_version_after_force = lvVal + '';",
|
|
171
|
-
" r.steps.latest_version_success = (lvVal === verSysId + '');",
|
|
172
|
-
" }",
|
|
165
|
+
" } catch(lsE) { r.steps.latest_snapshot_set = 'error:' + (lsE.getMessage ? lsE.getMessage() : lsE + ''); }",
|
|
173
166
|
" }",
|
|
174
167
|
" r.tier_used = 'gliderecord_scheduled'; r.success = true;",
|
|
175
168
|
" }",
|
|
@@ -280,37 +273,74 @@ async function createFlowViaScheduledJob(
|
|
|
280
273
|
" }",
|
|
281
274
|
" r.steps.variables = { success: true, created: varsCreated };",
|
|
282
275
|
"",
|
|
283
|
-
// ──
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
"
|
|
276
|
+
// ── Reference: query an existing published flow to see what it looks like ──
|
|
277
|
+
" r.steps.reference_flow = null;",
|
|
278
|
+
" try {",
|
|
279
|
+
" var refGr = new GlideRecord('sys_hub_flow');",
|
|
280
|
+
" refGr.addQuery('status', 'published');",
|
|
281
|
+
" refGr.addQuery('active', true);",
|
|
282
|
+
" refGr.setLimit(1); refGr.query();",
|
|
283
|
+
" if (refGr.next()) {",
|
|
284
|
+
" var refId = refGr.getUniqueValue();",
|
|
285
|
+
" var refFd = refGr.getValue('flow_definition') + '';",
|
|
286
|
+
" var refLs = refGr.getValue('latest_snapshot') + '';",
|
|
287
|
+
" var refLv = refGr.getValue('latest_version') + '';",
|
|
288
|
+
" r.steps.reference_flow = {",
|
|
289
|
+
" sys_id: refId,",
|
|
290
|
+
" name: refGr.getValue('name'),",
|
|
291
|
+
" has_flow_definition: refFd !== 'null' && refFd.length > 0,",
|
|
292
|
+
" flow_definition_length: refFd.length,",
|
|
293
|
+
" flow_definition_prefix: refFd.substring(0, 200),",
|
|
294
|
+
" has_latest_snapshot: refLs !== 'null' && refLs.length > 0,",
|
|
295
|
+
" latest_snapshot_length: refLs.length,",
|
|
296
|
+
" latest_version: refLv,",
|
|
297
|
+
" has_latest_version: refLv !== 'null' && refLv.length > 5",
|
|
298
|
+
" };",
|
|
299
|
+
// Query version records for reference flow (by flow= since latest_version is null)
|
|
300
|
+
" var refVer = new GlideRecord('sys_hub_flow_version');",
|
|
301
|
+
" refVer.addQuery('flow', refId);",
|
|
302
|
+
" refVer.orderByDesc('sys_created_on');",
|
|
303
|
+
" refVer.setLimit(1); refVer.query();",
|
|
304
|
+
" if (refVer.next()) {",
|
|
305
|
+
" var refVFd = refVer.getValue('flow_definition') + '';",
|
|
306
|
+
" r.steps.reference_flow.version_sys_id = refVer.getUniqueValue();",
|
|
307
|
+
" r.steps.reference_flow.version_state = refVer.getValue('state');",
|
|
308
|
+
" r.steps.reference_flow.version_compile_state = refVer.getValue('compile_state');",
|
|
309
|
+
" r.steps.reference_flow.version_is_current = refVer.getValue('is_current');",
|
|
310
|
+
" r.steps.reference_flow.version_active = refVer.getValue('active');",
|
|
311
|
+
" r.steps.reference_flow.version_has_flow_def = refVFd !== 'null' && refVFd.length > 0;",
|
|
312
|
+
" r.steps.reference_flow.version_flow_def_length = refVFd.length;",
|
|
313
|
+
" r.steps.reference_flow.version_flow_def_prefix = refVFd.substring(0, 200);",
|
|
314
|
+
// Check if latest_snapshot matches this version sys_id
|
|
315
|
+
" r.steps.reference_flow.snapshot_matches_version = (refLs === refVer.getUniqueValue());",
|
|
316
|
+
" } else { r.steps.reference_flow.version_found = false; }",
|
|
317
|
+
" }",
|
|
318
|
+
" } catch(refE) { r.steps.reference_flow = { error: refE + '' }; }",
|
|
319
|
+
"",
|
|
320
|
+
// ── Engine: try FlowAPI.compile() now that flow_definition is set ──
|
|
321
|
+
// DO NOT try publish (StackOverflowError). Only compile.
|
|
322
|
+
" r.steps.engine = { apis_found: [], mode: 'compile_with_flowdef' };",
|
|
288
323
|
" try {",
|
|
289
324
|
" if (typeof sn_fd !== 'undefined') {",
|
|
290
325
|
" r.steps.engine.sn_fd = 'available';",
|
|
291
|
-
"
|
|
292
|
-
"
|
|
326
|
+
" if (sn_fd.FlowAPI && typeof sn_fd.FlowAPI.compile === 'function') {",
|
|
327
|
+
" r.steps.engine.apis_found.push('FlowAPI');",
|
|
293
328
|
" try {",
|
|
294
|
-
"
|
|
295
|
-
"
|
|
296
|
-
"
|
|
297
|
-
"
|
|
298
|
-
"
|
|
299
|
-
"
|
|
300
|
-
|
|
301
|
-
"
|
|
302
|
-
"
|
|
303
|
-
"
|
|
304
|
-
" }
|
|
329
|
+
" var compileResult = sn_fd.FlowAPI.compile(flowSysId);",
|
|
330
|
+
" r.steps.engine.compile = 'success';",
|
|
331
|
+
" r.steps.engine.compile_result = (compileResult + '').substring(0, 200);",
|
|
332
|
+
" } catch(ce) {",
|
|
333
|
+
" r.steps.engine.compile = 'error:' + (ce.getMessage ? ce.getMessage() : ce + '');",
|
|
334
|
+
" }",
|
|
335
|
+
// Check latest_version immediately after compile
|
|
336
|
+
" var postCompile = new GlideRecord('sys_hub_flow');",
|
|
337
|
+
" if (postCompile.get(flowSysId)) {",
|
|
338
|
+
" r.steps.engine.latest_version_after_compile = postCompile.getValue('latest_version') + '';",
|
|
339
|
+
" }",
|
|
305
340
|
" }",
|
|
306
341
|
" } else {",
|
|
307
342
|
" r.steps.engine.sn_fd = 'unavailable';",
|
|
308
343
|
" }",
|
|
309
|
-
" try {",
|
|
310
|
-
" if (typeof GlideFlowDesigner !== 'undefined') {",
|
|
311
|
-
" r.steps.engine.apis_found.push('GlideFlowDesigner');",
|
|
312
|
-
" }",
|
|
313
|
-
" } catch(e) {}",
|
|
314
344
|
" } catch(engineErr) {",
|
|
315
345
|
" r.steps.engine.error = engineErr.getMessage ? engineErr.getMessage() : engineErr + '';",
|
|
316
346
|
" }",
|
|
@@ -318,12 +348,17 @@ async function createFlowViaScheduledJob(
|
|
|
318
348
|
"",
|
|
319
349
|
" r.flow_sys_id = flowSysId ? flowSysId + '' : null;",
|
|
320
350
|
" r.version_sys_id = verSysId ? verSysId + '' : null;",
|
|
321
|
-
// ──
|
|
351
|
+
// ── Final check: re-read latest_version + compare our flow to reference ──
|
|
322
352
|
" if (flowSysId) {",
|
|
323
353
|
" var cf = new GlideRecord('sys_hub_flow');",
|
|
324
354
|
" if (cf.get(flowSysId)) {",
|
|
325
355
|
" r.latest_version_set = !cf.latest_version.nil();",
|
|
326
356
|
" r.latest_version_value = cf.getValue('latest_version') + '';",
|
|
357
|
+
// Also read our flow_definition to verify it was stored
|
|
358
|
+
" var ourFd = cf.getValue('flow_definition') + '';",
|
|
359
|
+
" r.our_flow_definition_stored = ourFd !== 'null' && ourFd.length > 0;",
|
|
360
|
+
" r.our_flow_definition_length = ourFd.length;",
|
|
361
|
+
" r.our_flow_definition_prefix = ourFd.substring(0, 200);",
|
|
327
362
|
" }",
|
|
328
363
|
" }",
|
|
329
364
|
" } catch(e) { r.success = false; r.error = e.getMessage ? e.getMessage() : e + ''; }",
|
|
@@ -1429,9 +1464,9 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
|
|
|
1429
1464
|
run_as: flowRunAs,
|
|
1430
1465
|
status: shouldActivate ? 'published' : 'draft',
|
|
1431
1466
|
validated: true,
|
|
1432
|
-
type: isSubflow ? 'subflow' : 'flow'
|
|
1433
|
-
flow_definition
|
|
1434
|
-
|
|
1467
|
+
type: isSubflow ? 'subflow' : 'flow'
|
|
1468
|
+
// Do NOT set flow_definition or latest_snapshot on flow record
|
|
1469
|
+
// Reference flow analysis: flow_definition=null, latest_snapshot=version sys_id
|
|
1435
1470
|
};
|
|
1436
1471
|
|
|
1437
1472
|
var flowResponse = await client.post('/api/now/table/sys_hub_flow', flowData);
|
|
@@ -1475,36 +1510,16 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
|
|
|
1475
1510
|
versionCreated = true;
|
|
1476
1511
|
diagnostics.version_created = true;
|
|
1477
1512
|
diagnostics.version_method = 'table_api (draft→update)';
|
|
1478
|
-
diagnostics.version_fields_set = ['flow', 'name', 'version', 'state', 'active', 'compile_state', 'is_current', 'published_flow', 'internal_name'];
|
|
1479
1513
|
|
|
1480
|
-
//
|
|
1481
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
1514
|
+
// Set latest_snapshot on flow record to version sys_id (reference field)
|
|
1482
1515
|
try {
|
|
1483
|
-
|
|
1484
|
-
|
|
1516
|
+
await client.patch('/api/now/table/sys_hub_flow/' + flowSysId, {
|
|
1517
|
+
latest_snapshot: versionSysId
|
|
1485
1518
|
});
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
if (!autoLinked) {
|
|
1491
|
-
try {
|
|
1492
|
-
var linkResp = await client.patch('/api/now/table/sys_hub_flow/' + flowSysId, {
|
|
1493
|
-
latest_version: versionSysId,
|
|
1494
|
-
latest_published_version: shouldActivate ? versionSysId : undefined
|
|
1495
|
-
});
|
|
1496
|
-
diagnostics.latest_version_patch_status = linkResp.status;
|
|
1497
|
-
// Immediate readback
|
|
1498
|
-
var readback = await client.get('/api/now/table/sys_hub_flow/' + flowSysId, {
|
|
1499
|
-
params: { sysparm_fields: 'latest_version', sysparm_display_value: 'false' }
|
|
1500
|
-
});
|
|
1501
|
-
diagnostics.latest_version_after_patch = readback.data.result?.latest_version || 'null';
|
|
1502
|
-
} catch (linkError: any) {
|
|
1503
|
-
diagnostics.latest_version_patch_error = linkError.message || 'unknown';
|
|
1504
|
-
factoryWarnings.push('latest_version link failed: ' + (linkError.message || linkError));
|
|
1505
|
-
}
|
|
1506
|
-
}
|
|
1507
|
-
} catch (_) {}
|
|
1519
|
+
diagnostics.latest_snapshot_set = versionSysId;
|
|
1520
|
+
} catch (snapshotErr: any) {
|
|
1521
|
+
diagnostics.latest_snapshot_error = snapshotErr.message || 'unknown';
|
|
1522
|
+
}
|
|
1508
1523
|
}
|
|
1509
1524
|
} catch (verError: any) {
|
|
1510
1525
|
factoryWarnings.push('sys_hub_flow_version creation failed: ' + (verError.message || verError));
|