diff --git a/backend/routes/ivantiFpWorkflow.js b/backend/routes/ivantiFpWorkflow.js index 933f634..2b1a392 100644 --- a/backend/routes/ivantiFpWorkflow.js +++ b/backend/routes/ivantiFpWorkflow.js @@ -302,6 +302,22 @@ function createIvantiFpWorkflowRouter() { } } } catch (e) { console.error('Error enriching submissions with Ivanti notes:', e.message); } + + // Sync lifecycle_status from Ivanti currentState when it differs + const STATE_MAP = { 'APPROVED': 'approved', 'REJECTED': 'rejected', 'REWORK': 'rework' }; + for (const sub of submissions) { + if (!sub.ivanti_current_state) continue; + const mappedStatus = STATE_MAP[sub.ivanti_current_state.toUpperCase()]; + if (mappedStatus && mappedStatus !== sub.lifecycle_status) { + try { + await pool.query( + `UPDATE ivanti_fp_submissions SET lifecycle_status = $1, updated_at = NOW() WHERE id = $2`, + [mappedStatus, sub.id] + ); + sub.lifecycle_status = mappedStatus; + } catch (syncErr) { console.error(`Failed to sync lifecycle_status for submission ${sub.id}:`, syncErr.message); } + } + } } } res.json(submissions); diff --git a/frontend/src/components/pages/ReportingPage.js b/frontend/src/components/pages/ReportingPage.js index c0d7755..c6a5135 100644 --- a/frontend/src/components/pages/ReportingPage.js +++ b/frontend/src/components/pages/ReportingPage.js @@ -4090,7 +4090,7 @@ function FpEditModal({ open, onClose, submission, queueItems, onSuccess }) { const safeText = (val) => { if (!val) return null; if (typeof val === 'string') return val; - try { return JSON.stringify(val); } catch { return String(val); } + return null; }; const notes = [ safeText(submission.ivanti_rework_note) && { label: 'Rework Note', text: safeText(submission.ivanti_rework_note) },