snow-flow 10.0.1-dev.411 → 10.0.1-dev.413
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,7 +273,7 @@ async function createFlowViaScheduledJob(
|
|
|
280
273
|
" }",
|
|
281
274
|
" r.steps.variables = { success: true, created: varsCreated };",
|
|
282
275
|
"",
|
|
283
|
-
// ── Reference:
|
|
276
|
+
// ── Reference: deep-inspect a published flow to find what latest_snapshot points to ──
|
|
284
277
|
" r.steps.reference_flow = null;",
|
|
285
278
|
" try {",
|
|
286
279
|
" var refGr = new GlideRecord('sys_hub_flow');",
|
|
@@ -289,79 +282,73 @@ async function createFlowViaScheduledJob(
|
|
|
289
282
|
" refGr.setLimit(1); refGr.query();",
|
|
290
283
|
" if (refGr.next()) {",
|
|
291
284
|
" var refId = refGr.getUniqueValue();",
|
|
292
|
-
" var refFd = refGr.getValue('flow_definition') + '';",
|
|
293
285
|
" var refLs = refGr.getValue('latest_snapshot') + '';",
|
|
294
|
-
" var refLv = refGr.getValue('latest_version') + '';",
|
|
295
286
|
" r.steps.reference_flow = {",
|
|
296
287
|
" sys_id: refId,",
|
|
297
288
|
" name: refGr.getValue('name'),",
|
|
298
|
-
"
|
|
299
|
-
"
|
|
300
|
-
" flow_definition_prefix: refFd.substring(0, 200),",
|
|
301
|
-
" has_latest_snapshot: refLs !== 'null' && refLs.length > 0,",
|
|
302
|
-
" latest_snapshot_length: refLs.length,",
|
|
303
|
-
" latest_version: refLv,",
|
|
304
|
-
" has_latest_version: refLv !== 'null' && refLv.length > 5",
|
|
289
|
+
" latest_snapshot_value: refLs,",
|
|
290
|
+
" latest_version: refGr.getValue('latest_version') + ''",
|
|
305
291
|
" };",
|
|
306
|
-
//
|
|
307
|
-
" if (
|
|
308
|
-
" var
|
|
309
|
-
"
|
|
310
|
-
"
|
|
311
|
-
"
|
|
312
|
-
"
|
|
313
|
-
"
|
|
314
|
-
"
|
|
315
|
-
"
|
|
316
|
-
"
|
|
317
|
-
"
|
|
292
|
+
// Find what table latest_snapshot points to
|
|
293
|
+
" if (refLs !== 'null' && refLs.length === 32) {",
|
|
294
|
+
" var snapTables = ['sys_hub_flow_version', 'sys_hub_flow_snapshot', 'sys_hub_compiled_flow', 'sys_hub_flow_base'];",
|
|
295
|
+
" for (var st = 0; st < snapTables.length; st++) {",
|
|
296
|
+
" try {",
|
|
297
|
+
" var stGr = new GlideRecord(snapTables[st]);",
|
|
298
|
+
" if (stGr.isValid() && stGr.get(refLs)) {",
|
|
299
|
+
" r.steps.reference_flow.snapshot_found_in_table = snapTables[st];",
|
|
300
|
+
" r.steps.reference_flow.snapshot_record_name = stGr.getValue('name') + '';",
|
|
301
|
+
" break;",
|
|
302
|
+
" }",
|
|
303
|
+
" } catch(e) {}",
|
|
304
|
+
" }",
|
|
305
|
+
// Also try sys_metadata (universal)
|
|
306
|
+
" if (!r.steps.reference_flow.snapshot_found_in_table) {",
|
|
307
|
+
" try {",
|
|
308
|
+
" var metaGr = new GlideRecord('sys_metadata');",
|
|
309
|
+
" if (metaGr.get(refLs)) {",
|
|
310
|
+
" r.steps.reference_flow.snapshot_found_in_table = metaGr.getValue('sys_class_name') + '';",
|
|
311
|
+
" }",
|
|
312
|
+
" } catch(e) {}",
|
|
313
|
+
" }",
|
|
314
|
+
" }",
|
|
315
|
+
// Get field descriptor for latest_snapshot to see its reference table
|
|
316
|
+
" var fd = refGr.getElement('latest_snapshot');",
|
|
317
|
+
" if (fd) {",
|
|
318
|
+
" var ed = fd.getED();",
|
|
319
|
+
" if (ed) {",
|
|
320
|
+
" r.steps.reference_flow.snapshot_field_type = ed.getInternalType() + '';",
|
|
321
|
+
" r.steps.reference_flow.snapshot_field_reference = ed.getReference() + '';",
|
|
318
322
|
" }",
|
|
319
323
|
" }",
|
|
324
|
+
// Count trigger/action instances for reference flow
|
|
325
|
+
" var refTrig = new GlideAggregate('sys_hub_trigger_instance');",
|
|
326
|
+
" refTrig.addQuery('flow', refId); refTrig.addAggregate('COUNT'); refTrig.query();",
|
|
327
|
+
" r.steps.reference_flow.trigger_count = refTrig.next() ? parseInt(refTrig.getAggregate('COUNT')) : 0;",
|
|
328
|
+
" var refAct = new GlideAggregate('sys_hub_action_instance');",
|
|
329
|
+
" refAct.addQuery('flow', refId); refAct.addAggregate('COUNT'); refAct.query();",
|
|
330
|
+
" r.steps.reference_flow.action_count = refAct.next() ? parseInt(refAct.getAggregate('COUNT')) : 0;",
|
|
320
331
|
" }",
|
|
321
332
|
" } catch(refE) { r.steps.reference_flow = { error: refE + '' }; }",
|
|
322
333
|
"",
|
|
323
|
-
// ── Engine:
|
|
324
|
-
|
|
325
|
-
" r.steps.engine = { apis_found: [], mode: 'compile_with_flowdef' };",
|
|
334
|
+
// ── Engine: skip compile (returns error, doesn't help) ──
|
|
335
|
+
" r.steps.engine = { mode: 'probe_only' };",
|
|
326
336
|
" try {",
|
|
327
337
|
" if (typeof sn_fd !== 'undefined') {",
|
|
328
338
|
" r.steps.engine.sn_fd = 'available';",
|
|
329
|
-
"
|
|
330
|
-
"
|
|
331
|
-
" try {",
|
|
332
|
-
" var compileResult = sn_fd.FlowAPI.compile(flowSysId);",
|
|
333
|
-
" r.steps.engine.compile = 'success';",
|
|
334
|
-
" r.steps.engine.compile_result = (compileResult + '').substring(0, 200);",
|
|
335
|
-
" } catch(ce) {",
|
|
336
|
-
" r.steps.engine.compile = 'error:' + (ce.getMessage ? ce.getMessage() : ce + '');",
|
|
337
|
-
" }",
|
|
338
|
-
// Check latest_version immediately after compile
|
|
339
|
-
" var postCompile = new GlideRecord('sys_hub_flow');",
|
|
340
|
-
" if (postCompile.get(flowSysId)) {",
|
|
341
|
-
" r.steps.engine.latest_version_after_compile = postCompile.getValue('latest_version') + '';",
|
|
342
|
-
" }",
|
|
343
|
-
" }",
|
|
344
|
-
" } else {",
|
|
345
|
-
" r.steps.engine.sn_fd = 'unavailable';",
|
|
346
|
-
" }",
|
|
347
|
-
" } catch(engineErr) {",
|
|
348
|
-
" r.steps.engine.error = engineErr.getMessage ? engineErr.getMessage() : engineErr + '';",
|
|
349
|
-
" }",
|
|
339
|
+
" } else { r.steps.engine.sn_fd = 'unavailable'; }",
|
|
340
|
+
" } catch(engineErr) {}",
|
|
350
341
|
" }",
|
|
351
342
|
"",
|
|
352
343
|
" r.flow_sys_id = flowSysId ? flowSysId + '' : null;",
|
|
353
344
|
" r.version_sys_id = verSysId ? verSysId + '' : null;",
|
|
354
|
-
// ── Final check:
|
|
345
|
+
// ── Final check: read back our flow's latest_snapshot to confirm ──
|
|
355
346
|
" if (flowSysId) {",
|
|
356
347
|
" var cf = new GlideRecord('sys_hub_flow');",
|
|
357
348
|
" if (cf.get(flowSysId)) {",
|
|
358
|
-
" r.latest_version_set = !cf.latest_version.nil();",
|
|
359
349
|
" r.latest_version_value = cf.getValue('latest_version') + '';",
|
|
360
|
-
|
|
361
|
-
"
|
|
362
|
-
" r.our_flow_definition_stored = ourFd !== 'null' && ourFd.length > 0;",
|
|
363
|
-
" r.our_flow_definition_length = ourFd.length;",
|
|
364
|
-
" r.our_flow_definition_prefix = ourFd.substring(0, 200);",
|
|
350
|
+
" r.our_latest_snapshot = cf.getValue('latest_snapshot') + '';",
|
|
351
|
+
" r.our_latest_snapshot_length = (cf.getValue('latest_snapshot') + '').length;",
|
|
365
352
|
" }",
|
|
366
353
|
" }",
|
|
367
354
|
" } catch(e) { r.success = false; r.error = e.getMessage ? e.getMessage() : e + ''; }",
|
|
@@ -1467,9 +1454,9 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
|
|
|
1467
1454
|
run_as: flowRunAs,
|
|
1468
1455
|
status: shouldActivate ? 'published' : 'draft',
|
|
1469
1456
|
validated: true,
|
|
1470
|
-
type: isSubflow ? 'subflow' : 'flow'
|
|
1471
|
-
flow_definition
|
|
1472
|
-
|
|
1457
|
+
type: isSubflow ? 'subflow' : 'flow'
|
|
1458
|
+
// Do NOT set flow_definition or latest_snapshot on flow record
|
|
1459
|
+
// Reference flow analysis: flow_definition=null, latest_snapshot=version sys_id
|
|
1473
1460
|
};
|
|
1474
1461
|
|
|
1475
1462
|
var flowResponse = await client.post('/api/now/table/sys_hub_flow', flowData);
|
|
@@ -1513,36 +1500,16 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
|
|
|
1513
1500
|
versionCreated = true;
|
|
1514
1501
|
diagnostics.version_created = true;
|
|
1515
1502
|
diagnostics.version_method = 'table_api (draft→update)';
|
|
1516
|
-
diagnostics.version_fields_set = ['flow', 'name', 'version', 'state', 'active', 'compile_state', 'is_current', 'published_flow', 'internal_name'];
|
|
1517
1503
|
|
|
1518
|
-
//
|
|
1519
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
1504
|
+
// Set latest_snapshot on flow record to version sys_id (reference field)
|
|
1520
1505
|
try {
|
|
1521
|
-
|
|
1522
|
-
|
|
1506
|
+
await client.patch('/api/now/table/sys_hub_flow/' + flowSysId, {
|
|
1507
|
+
latest_snapshot: versionSysId
|
|
1523
1508
|
});
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
if (!autoLinked) {
|
|
1529
|
-
try {
|
|
1530
|
-
var linkResp = await client.patch('/api/now/table/sys_hub_flow/' + flowSysId, {
|
|
1531
|
-
latest_version: versionSysId,
|
|
1532
|
-
latest_published_version: shouldActivate ? versionSysId : undefined
|
|
1533
|
-
});
|
|
1534
|
-
diagnostics.latest_version_patch_status = linkResp.status;
|
|
1535
|
-
// Immediate readback
|
|
1536
|
-
var readback = await client.get('/api/now/table/sys_hub_flow/' + flowSysId, {
|
|
1537
|
-
params: { sysparm_fields: 'latest_version', sysparm_display_value: 'false' }
|
|
1538
|
-
});
|
|
1539
|
-
diagnostics.latest_version_after_patch = readback.data.result?.latest_version || 'null';
|
|
1540
|
-
} catch (linkError: any) {
|
|
1541
|
-
diagnostics.latest_version_patch_error = linkError.message || 'unknown';
|
|
1542
|
-
factoryWarnings.push('latest_version link failed: ' + (linkError.message || linkError));
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
} catch (_) {}
|
|
1509
|
+
diagnostics.latest_snapshot_set = versionSysId;
|
|
1510
|
+
} catch (snapshotErr: any) {
|
|
1511
|
+
diagnostics.latest_snapshot_error = snapshotErr.message || 'unknown';
|
|
1512
|
+
}
|
|
1546
1513
|
}
|
|
1547
1514
|
} catch (verError: any) {
|
|
1548
1515
|
factoryWarnings.push('sys_hub_flow_version creation failed: ' + (verError.message || verError));
|