snow-flow 10.0.1-dev.411 → 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
|
" }",
|
|
@@ -303,20 +296,24 @@ async function createFlowViaScheduledJob(
|
|
|
303
296
|
" latest_version: refLv,",
|
|
304
297
|
" has_latest_version: refLv !== 'null' && refLv.length > 5",
|
|
305
298
|
" };",
|
|
306
|
-
//
|
|
307
|
-
"
|
|
308
|
-
"
|
|
309
|
-
"
|
|
310
|
-
"
|
|
311
|
-
"
|
|
312
|
-
"
|
|
313
|
-
"
|
|
314
|
-
"
|
|
315
|
-
"
|
|
316
|
-
"
|
|
317
|
-
"
|
|
318
|
-
"
|
|
319
|
-
"
|
|
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; }",
|
|
320
317
|
" }",
|
|
321
318
|
" } catch(refE) { r.steps.reference_flow = { error: refE + '' }; }",
|
|
322
319
|
"",
|
|
@@ -1467,9 +1464,9 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
|
|
|
1467
1464
|
run_as: flowRunAs,
|
|
1468
1465
|
status: shouldActivate ? 'published' : 'draft',
|
|
1469
1466
|
validated: true,
|
|
1470
|
-
type: isSubflow ? 'subflow' : 'flow'
|
|
1471
|
-
flow_definition
|
|
1472
|
-
|
|
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
|
|
1473
1470
|
};
|
|
1474
1471
|
|
|
1475
1472
|
var flowResponse = await client.post('/api/now/table/sys_hub_flow', flowData);
|
|
@@ -1513,36 +1510,16 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
|
|
|
1513
1510
|
versionCreated = true;
|
|
1514
1511
|
diagnostics.version_created = true;
|
|
1515
1512
|
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
1513
|
|
|
1518
|
-
//
|
|
1519
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
1514
|
+
// Set latest_snapshot on flow record to version sys_id (reference field)
|
|
1520
1515
|
try {
|
|
1521
|
-
|
|
1522
|
-
|
|
1516
|
+
await client.patch('/api/now/table/sys_hub_flow/' + flowSysId, {
|
|
1517
|
+
latest_snapshot: versionSysId
|
|
1523
1518
|
});
|
|
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 (_) {}
|
|
1519
|
+
diagnostics.latest_snapshot_set = versionSysId;
|
|
1520
|
+
} catch (snapshotErr: any) {
|
|
1521
|
+
diagnostics.latest_snapshot_error = snapshotErr.message || 'unknown';
|
|
1522
|
+
}
|
|
1546
1523
|
}
|
|
1547
1524
|
} catch (verError: any) {
|
|
1548
1525
|
factoryWarnings.push('sys_hub_flow_version creation failed: ' + (verError.message || verError));
|