fix: search by workflow name instead of numeric ID to resolve UUID
This commit is contained in:
@@ -161,17 +161,19 @@ async function resolveWorkflowBatchUuid(db, submission, apiKey, clientId, skipTl
|
|||||||
// Return cached UUID if available
|
// Return cached UUID if available
|
||||||
if (submission.ivanti_workflow_batch_uuid) return submission.ivanti_workflow_batch_uuid;
|
if (submission.ivanti_workflow_batch_uuid) return submission.ivanti_workflow_batch_uuid;
|
||||||
|
|
||||||
// Search Ivanti for the workflow batch by numeric ID to get the UUID
|
|
||||||
const searchUrl = `/client/${encodeURIComponent(clientId)}/workflowBatch/search`;
|
const searchUrl = `/client/${encodeURIComponent(clientId)}/workflowBatch/search`;
|
||||||
const batchId = String(submission.ivanti_workflow_batch_id);
|
const batchId = String(submission.ivanti_workflow_batch_id);
|
||||||
|
const workflowName = submission.workflow_name || '';
|
||||||
|
|
||||||
// Try searching by 'id' field with 'internal' projection (matches existing sync pattern)
|
// Search by workflow name (the 'id' field in search context doesn't match the numeric batch ID)
|
||||||
const searchBody = {
|
const searchBody = {
|
||||||
filters: [{ field: 'id', exclusive: false, operator: 'EXACT', value: batchId }],
|
filters: workflowName ? [
|
||||||
|
{ field: 'name', exclusive: false, operator: 'EXACT', value: workflowName }
|
||||||
|
] : [],
|
||||||
projection: 'internal',
|
projection: 'internal',
|
||||||
sort: [{ field: 'id', direction: 'ASC' }],
|
sort: [{ field: 'created', direction: 'DESC' }],
|
||||||
page: 0,
|
page: 0,
|
||||||
size: 1
|
size: 10
|
||||||
};
|
};
|
||||||
|
|
||||||
let result;
|
let result;
|
||||||
@@ -182,17 +184,14 @@ async function resolveWorkflowBatchUuid(db, submission, apiKey, clientId, skipTl
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[resolveUUID] Search status:', result.status, 'for batch ID:', batchId);
|
|
||||||
console.log('[resolveUUID] Response body (first 1000 chars):', (result.body || '').substring(0, 1000));
|
|
||||||
|
|
||||||
if (result.status !== 200) {
|
if (result.status !== 200) {
|
||||||
|
console.error('[resolveUUID] Search returned status:', result.status);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let uuid = null;
|
let uuid = null;
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(result.body);
|
const data = JSON.parse(result.body);
|
||||||
// Spring Data REST format
|
|
||||||
let batches = [];
|
let batches = [];
|
||||||
if (data._embedded?.workflowBatches) batches = data._embedded.workflowBatches;
|
if (data._embedded?.workflowBatches) batches = data._embedded.workflowBatches;
|
||||||
else if (data._embedded?.workflowBatch) batches = data._embedded.workflowBatch;
|
else if (data._embedded?.workflowBatch) batches = data._embedded.workflowBatch;
|
||||||
@@ -200,19 +199,19 @@ async function resolveWorkflowBatchUuid(db, submission, apiKey, clientId, skipTl
|
|||||||
else if (data.data) batches = data.data;
|
else if (data.data) batches = data.data;
|
||||||
else if (Array.isArray(data)) batches = data;
|
else if (Array.isArray(data)) batches = data;
|
||||||
|
|
||||||
console.log('[resolveUUID] Found', batches.length, 'batches');
|
console.log('[resolveUUID] Found', batches.length, 'batches for name:', workflowName);
|
||||||
|
|
||||||
const batch = batches[0];
|
// Find the batch matching our numeric ID, or take the first result
|
||||||
|
const batch = batches.find(b => String(b.id) === batchId) || batches[0];
|
||||||
if (batch) {
|
if (batch) {
|
||||||
// Log all keys so we can identify the right field
|
|
||||||
console.log('[resolveUUID] Batch keys:', Object.keys(batch).join(', '));
|
console.log('[resolveUUID] Batch keys:', Object.keys(batch).join(', '));
|
||||||
|
console.log('[resolveUUID] Batch id:', batch.id, 'name:', batch.name);
|
||||||
console.log('[resolveUUID] Batch sample:', JSON.stringify(batch).substring(0, 800));
|
console.log('[resolveUUID] Batch sample:', JSON.stringify(batch).substring(0, 800));
|
||||||
// Try common UUID field names
|
// Try every possible UUID field
|
||||||
uuid = batch.uuid || batch.workflowBatchUuid || batch.batchUuid || batch.groupUuid || null;
|
uuid = batch.uuid || batch.workflowBatchUuid || batch.batchUuid || batch.groupUuid
|
||||||
|
|| batch.group_uuid || batch.workflow_batch_uuid || batch.uid || null;
|
||||||
} else {
|
} else {
|
||||||
console.log('[resolveUUID] No batches found for ID:', batchId);
|
console.log('[resolveUUID] No batches found');
|
||||||
// Log the full response structure to understand the format
|
|
||||||
console.log('[resolveUUID] Response keys:', Object.keys(data).join(', '));
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[resolveUUID] Failed to parse search response:', e.message);
|
console.error('[resolveUUID] Failed to parse search response:', e.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user