snow-flow 10.0.1-dev.449 → 10.0.1-dev.450
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
|
@@ -38,15 +38,14 @@ function generateUUID(): string {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
async function getNextOrder(client: any, flowId: string
|
|
41
|
+
async function getNextOrder(client: any, flowId: string): Promise<number> {
|
|
42
42
|
let maxOrder = 0;
|
|
43
|
-
//
|
|
44
|
-
const parentFilter = parentId ? '^parent=' + parentId : '^parentISEMPTY';
|
|
43
|
+
// Order is global across all elements in the flow (not per-parent)
|
|
45
44
|
for (const table of ['sys_hub_action_instance', 'sys_hub_flow_logic', 'sys_hub_sub_flow_instance']) {
|
|
46
45
|
try {
|
|
47
46
|
const resp = await client.get('/api/now/table/' + table, {
|
|
48
47
|
params: {
|
|
49
|
-
sysparm_query: 'flow=' + flowId +
|
|
48
|
+
sysparm_query: 'flow=' + flowId + '^ORDERBYDESCorder',
|
|
50
49
|
sysparm_fields: 'order',
|
|
51
50
|
sysparm_limit: 1
|
|
52
51
|
}
|
|
@@ -286,26 +285,32 @@ async function addActionViaGraphQL(
|
|
|
286
285
|
}
|
|
287
286
|
|
|
288
287
|
const uuid = generateUUID();
|
|
289
|
-
const resolvedOrder = order || await getNextOrder(client, flowId
|
|
290
|
-
const actionResponseFields = 'actions { inserts { sysId uiUniqueIdentifier __typename } updates deletes __typename }'
|
|
288
|
+
const resolvedOrder = order || await getNextOrder(client, flowId);
|
|
289
|
+
const actionResponseFields = 'actions { inserts { sysId uiUniqueIdentifier __typename } updates deletes __typename }' +
|
|
290
|
+
(parentUiId ? ' flowLogics { inserts { sysId uiUniqueIdentifier __typename } updates deletes __typename }' : '');
|
|
291
|
+
// Build mutation payload — when nesting inside a flow logic block, also update the parent
|
|
292
|
+
const flowPatch: any = {
|
|
293
|
+
flowId: flowId,
|
|
294
|
+
actions: {
|
|
295
|
+
insert: [{
|
|
296
|
+
actionTypeSysId: actionDefId,
|
|
297
|
+
metadata: '{"predicates":[]}',
|
|
298
|
+
flowSysId: flowId,
|
|
299
|
+
generationSource: '',
|
|
300
|
+
order: String(resolvedOrder),
|
|
301
|
+
parent: parentUiId || '',
|
|
302
|
+
uiUniqueIdentifier: uuid,
|
|
303
|
+
type: 'action',
|
|
304
|
+
parentUiId: parentUiId || '',
|
|
305
|
+
inputs: []
|
|
306
|
+
}]
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
if (parentUiId) {
|
|
310
|
+
flowPatch.flowLogics = { update: [{ uiUniqueIdentifier: parentUiId, type: 'flowlogic' }] };
|
|
311
|
+
}
|
|
291
312
|
try {
|
|
292
|
-
const result = await executeFlowPatchMutation(client,
|
|
293
|
-
flowId: flowId,
|
|
294
|
-
actions: {
|
|
295
|
-
insert: [{
|
|
296
|
-
actionTypeSysId: actionDefId,
|
|
297
|
-
metadata: '{"predicates":[]}',
|
|
298
|
-
flowSysId: flowId,
|
|
299
|
-
generationSource: '',
|
|
300
|
-
order: String(resolvedOrder),
|
|
301
|
-
parent: parentUiId || '',
|
|
302
|
-
uiUniqueIdentifier: uuid,
|
|
303
|
-
type: 'action',
|
|
304
|
-
parentUiId: parentUiId || '',
|
|
305
|
-
inputs: []
|
|
306
|
-
}]
|
|
307
|
-
}
|
|
308
|
-
}, actionResponseFields);
|
|
313
|
+
const result = await executeFlowPatchMutation(client, flowPatch, actionResponseFields);
|
|
309
314
|
|
|
310
315
|
const actionId = result?.actions?.inserts?.[0]?.sysId;
|
|
311
316
|
steps.insert = { success: !!actionId, actionId, uuid };
|
|
@@ -387,7 +392,7 @@ async function addFlowLogicViaGraphQL(
|
|
|
387
392
|
if (!defId) return { success: false, error: 'Flow logic definition not found for: ' + logicType, steps };
|
|
388
393
|
|
|
389
394
|
const uuid = generateUUID();
|
|
390
|
-
const resolvedOrder = order || await getNextOrder(client, flowId
|
|
395
|
+
const resolvedOrder = order || await getNextOrder(client, flowId);
|
|
391
396
|
const logicResponseFields = 'flowLogics { inserts { sysId uiUniqueIdentifier __typename } updates deletes __typename }';
|
|
392
397
|
try {
|
|
393
398
|
const result = await executeFlowPatchMutation(client, {
|
|
@@ -495,27 +500,32 @@ async function addSubflowCallViaGraphQL(
|
|
|
495
500
|
if (!subflowName) subflowName = subflowId;
|
|
496
501
|
|
|
497
502
|
const uuid = generateUUID();
|
|
498
|
-
const resolvedOrder = order || await getNextOrder(client, flowId
|
|
499
|
-
const subflowResponseFields = 'subflows { inserts { sysId uiUniqueIdentifier __typename } updates deletes __typename }'
|
|
503
|
+
const resolvedOrder = order || await getNextOrder(client, flowId);
|
|
504
|
+
const subflowResponseFields = 'subflows { inserts { sysId uiUniqueIdentifier __typename } updates deletes __typename }' +
|
|
505
|
+
(parentUiId ? ' flowLogics { inserts { sysId uiUniqueIdentifier __typename } updates deletes __typename }' : '');
|
|
506
|
+
const subPatch: any = {
|
|
507
|
+
flowId: flowId,
|
|
508
|
+
subflows: {
|
|
509
|
+
insert: [{
|
|
510
|
+
metadata: '{"predicates":[]}',
|
|
511
|
+
flowSysId: flowId,
|
|
512
|
+
generationSource: '',
|
|
513
|
+
name: subflowName,
|
|
514
|
+
order: String(resolvedOrder),
|
|
515
|
+
parent: parentUiId || '',
|
|
516
|
+
subflowSysId: subflowSysId,
|
|
517
|
+
uiUniqueIdentifier: uuid,
|
|
518
|
+
type: 'subflow',
|
|
519
|
+
parentUiId: parentUiId || '',
|
|
520
|
+
inputs: []
|
|
521
|
+
}]
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
if (parentUiId) {
|
|
525
|
+
subPatch.flowLogics = { update: [{ uiUniqueIdentifier: parentUiId, type: 'flowlogic' }] };
|
|
526
|
+
}
|
|
500
527
|
try {
|
|
501
|
-
const result = await executeFlowPatchMutation(client,
|
|
502
|
-
flowId: flowId,
|
|
503
|
-
subflows: {
|
|
504
|
-
insert: [{
|
|
505
|
-
metadata: '{"predicates":[]}',
|
|
506
|
-
flowSysId: flowId,
|
|
507
|
-
generationSource: '',
|
|
508
|
-
name: subflowName,
|
|
509
|
-
order: String(resolvedOrder),
|
|
510
|
-
parent: parentUiId || '',
|
|
511
|
-
subflowSysId: subflowSysId,
|
|
512
|
-
uiUniqueIdentifier: uuid,
|
|
513
|
-
type: 'subflow',
|
|
514
|
-
parentUiId: parentUiId || '',
|
|
515
|
-
inputs: []
|
|
516
|
-
}]
|
|
517
|
-
}
|
|
518
|
-
}, subflowResponseFields);
|
|
528
|
+
const result = await executeFlowPatchMutation(client, subPatch, subflowResponseFields);
|
|
519
529
|
|
|
520
530
|
const callId = result?.subflows?.inserts?.[0]?.sysId;
|
|
521
531
|
steps.insert = { success: !!callId, callId, uuid };
|