snow-flow 10.0.1-dev.408 → 10.0.1-dev.410

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "10.0.1-dev.408",
3
+ "version": "10.0.1-dev.410",
4
4
  "name": "snow-flow",
5
5
  "description": "Snow-Flow - ServiceNow Multi-Agent Development Framework powered by AI",
6
6
  "license": "Elastic-2.0",
@@ -123,9 +123,10 @@ async function createFlowViaScheduledJob(
123
123
  " }",
124
124
  " } catch(t1e) { r.steps.tier1 = { success: false, error: t1e.getMessage ? t1e.getMessage() : t1e + '' }; }",
125
125
  "",
126
- // ── TIER 2: GlideRecord — minimal clean records ──
127
- // Do NOT set flow_definition/latest_snapshot on flow record (computed/managed).
128
- // Version: INSERT as draft → UPDATE is_current=true (triggers BRs that set latest_version).
126
+ // ── TIER 2: GlideRecord ──
127
+ // Set flow_definition + latest_snapshot on flow record.
128
+ // Set flow_definition on version record.
129
+ // Force-set latest_version with setWorkflow(false) to bypass BRs.
129
130
  " if (!flowSysId) {",
130
131
  " try {",
131
132
  " var f = new GlideRecord('sys_hub_flow');",
@@ -135,30 +136,39 @@ async function createFlowViaScheduledJob(
135
136
  " f.setValue('run_as', runAs); f.setValue('active', false);",
136
137
  " f.setValue('status', 'draft'); f.setValue('validated', true);",
137
138
  " f.setValue('type', isSubflow ? 'subflow' : 'flow');",
139
+ " if (flowDefStr) { f.setValue('flow_definition', flowDefStr); f.setValue('latest_snapshot', flowDefStr); }",
138
140
  " flowSysId = f.insert();",
139
- " r.steps.flow_insert = { success: !!flowSysId, sys_id: flowSysId + '' };",
141
+ " r.steps.flow_insert = { success: !!flowSysId, sys_id: flowSysId + '', flow_def_set: !!flowDefStr };",
140
142
  " if (flowSysId) {",
141
- // Step 1: INSERT version as minimal draft
142
143
  " var v = new GlideRecord('sys_hub_flow_version');",
143
144
  " v.initialize();",
144
145
  " v.setValue('flow', flowSysId); v.setValue('name', '1.0');",
145
146
  " v.setValue('version', '1.0'); v.setValue('state', 'draft');",
146
- " v.setValue('active', false); v.setValue('compile_state', 'draft');",
147
- " v.setValue('is_current', false);",
147
+ " v.setValue('active', true); v.setValue('compile_state', 'draft');",
148
+ " v.setValue('is_current', true);",
149
+ " v.setValue('internal_name', intName + '_v1_0');",
150
+ " if (flowDefStr) { v.setValue('flow_definition', flowDefStr); }",
148
151
  " verSysId = v.insert();",
149
- " r.steps.version_insert = { success: !!verSysId, sys_id: verSysId + '' };",
150
- // Step 2: UPDATE version → is_current=true, active=true (triggers BRs)
152
+ " r.steps.version_insert = { success: !!verSysId, sys_id: verSysId + '', has_flow_def: !!flowDefStr };",
153
+ "",
154
+ // Force-set latest_version — bypass BRs with setWorkflow(false)
151
155
  " if (verSysId) {",
152
- " var vu = new GlideRecord('sys_hub_flow_version');",
153
- " if (vu.get(verSysId)) {",
154
- " vu.setValue('is_current', true); vu.setValue('active', true);",
155
- " vu.update();",
156
- " r.steps.version_update = { success: true };",
157
- " }",
158
- // Check if BR set latest_version
156
+ " try {",
157
+ " var flowUpd = new GlideRecord('sys_hub_flow');",
158
+ " flowUpd.setWorkflow(false);",
159
+ " flowUpd.autoSysFields(false);",
160
+ " if (flowUpd.get(flowSysId)) {",
161
+ " flowUpd.setValue('latest_version', verSysId);",
162
+ " flowUpd.update();",
163
+ " r.steps.latest_version_force = 'attempted';",
164
+ " }",
165
+ " } catch(lvE) { r.steps.latest_version_force = 'error:' + (lvE.getMessage ? lvE.getMessage() : lvE + ''); }",
166
+ // Verify latest_version was set
159
167
  " var lvCheck = new GlideRecord('sys_hub_flow');",
160
168
  " if (lvCheck.get(flowSysId)) {",
161
- " r.steps.latest_version_after_update = lvCheck.getValue('latest_version') + '';",
169
+ " var lvVal = lvCheck.getValue('latest_version');",
170
+ " r.steps.latest_version_after_force = lvVal + '';",
171
+ " r.steps.latest_version_success = (lvVal === verSysId + '');",
162
172
  " }",
163
173
  " }",
164
174
  " r.tier_used = 'gliderecord_scheduled'; r.success = true;",
@@ -1624,11 +1634,11 @@ export async function execute(args: any, context: ServiceNowContext): Promise<To
1624
1634
 
1625
1635
  }
1626
1636
 
1627
- // ── Register flow with Flow Designer engine (Table API only) ──
1628
- // For scheduled job path, engine registration is done server-side
1629
- // inside the job script (via sn_fd APIs). Only call the external
1630
- // REST-based registration for the Table API fallback path.
1631
- if (flowSysId && usedMethod.startsWith('table_api')) {
1637
+ // ── Register flow with Flow Designer engine ──
1638
+ // Call the REST API (publish/activate/checkout+checkin/snapshot) to
1639
+ // trigger engine compilation and set latest_version (computed field
1640
+ // that cannot be set via GlideRecord or Table API PATCH).
1641
+ if (flowSysId) {
1632
1642
  var engineResult = await registerFlowWithEngine(client, flowSysId, shouldActivate);
1633
1643
  diagnostics.engine_registration = {
1634
1644
  success: engineResult.success,