snow-flow 10.0.1-dev.432 → 10.0.1-dev.434
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
|
@@ -62,48 +62,33 @@ async function addTriggerViaGraphQL(
|
|
|
62
62
|
): Promise<{ success: boolean; triggerId?: string; steps?: any; error?: string }> {
|
|
63
63
|
const steps: any = {};
|
|
64
64
|
|
|
65
|
-
const triggerMap: Record<string, { type: string; name: string; triggerType: string
|
|
66
|
-
'record_created': { type: 'record_create', name: 'Created', triggerType: 'Record',
|
|
67
|
-
|
|
68
|
-
'
|
|
69
|
-
|
|
70
|
-
'record_create_or_update': { type: 'record_create_or_update', name: 'Created or Updated', triggerType: 'Record',
|
|
71
|
-
defNames: ['sn_fd.trigger.record_create_or_update', 'global.sn_fd.trigger.record_create_or_update'] },
|
|
72
|
-
'scheduled': { type: 'scheduled', name: 'Scheduled', triggerType: 'Scheduled',
|
|
73
|
-
defNames: ['sn_fd.trigger.scheduled', 'global.sn_fd.trigger.scheduled'] },
|
|
65
|
+
const triggerMap: Record<string, { type: string; name: string; triggerType: string }> = {
|
|
66
|
+
'record_created': { type: 'record_create', name: 'Created', triggerType: 'Record' },
|
|
67
|
+
'record_updated': { type: 'record_update', name: 'Updated', triggerType: 'Record' },
|
|
68
|
+
'record_create_or_update': { type: 'record_create_or_update', name: 'Created or Updated', triggerType: 'Record' },
|
|
69
|
+
'scheduled': { type: 'scheduled', name: 'Scheduled', triggerType: 'Scheduled' },
|
|
74
70
|
};
|
|
75
71
|
|
|
76
72
|
const config = triggerMap[triggerType] || triggerMap['record_create_or_update'];
|
|
77
73
|
|
|
74
|
+
// Trigger definitions live in sys_hub_trigger_definition, keyed by `type` field
|
|
78
75
|
let trigDefId: string | null = null;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
trigDefId = resp.data.result?.[0]?.sys_id || null;
|
|
88
|
-
if (trigDefId) break;
|
|
89
|
-
} catch (_) {}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
76
|
+
try {
|
|
77
|
+
const resp = await client.get('/api/now/table/sys_hub_trigger_definition', {
|
|
78
|
+
params: { sysparm_query: 'type=' + config.type, sysparm_fields: 'sys_id,type,name', sysparm_limit: 1 }
|
|
79
|
+
});
|
|
80
|
+
trigDefId = resp.data.result?.[0]?.sys_id || null;
|
|
81
|
+
steps.def_lookup_primary = resp.data.result?.[0] || null;
|
|
82
|
+
} catch (_) {}
|
|
83
|
+
// Fallback: search by name
|
|
92
84
|
if (!trigDefId) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
for (const r of (resp.data.result || [])) {
|
|
103
|
-
if ((r.internal_name || '').indexOf(config.type) > -1) { trigDefId = r.sys_id; break; }
|
|
104
|
-
}
|
|
105
|
-
} catch (_) {}
|
|
106
|
-
}
|
|
85
|
+
try {
|
|
86
|
+
const resp = await client.get('/api/now/table/sys_hub_trigger_definition', {
|
|
87
|
+
params: { sysparm_query: 'name=' + config.name, sysparm_fields: 'sys_id,type,name', sysparm_limit: 1 }
|
|
88
|
+
});
|
|
89
|
+
trigDefId = resp.data.result?.[0]?.sys_id || null;
|
|
90
|
+
steps.def_lookup_fallback = resp.data.result?.[0] || null;
|
|
91
|
+
} catch (_) {}
|
|
107
92
|
}
|
|
108
93
|
if (!trigDefId) return { success: false, error: 'Trigger definition not found for: ' + triggerType, steps };
|
|
109
94
|
steps.def_lookup = { id: trigDefId };
|