diff --git a/src/components/ActivityForm.jsx b/src/components/ActivityForm.jsx index d72d005..df1bfe1 100644 --- a/src/components/ActivityForm.jsx +++ b/src/components/ActivityForm.jsx @@ -49,10 +49,28 @@ export default function ActivityForm({ activityUid, instanceId, lead, onDone, on // The server resolved a prefill pipeline for this activity — it stamps // the channel from the door and the agent from the signed-in user, so // the form never asks for either. Seed the inputs with what it sent. + // + // The two sides key differently, and matching only on f.id is why this + // silently did nothing. A form field is the ACTIVITY key, which carries + // a numeric suffix because a workflow version may use one global on + // several activities — partner_code_3, rm_or_agent_id_3, + // source_channel_4. The pipeline's fieldMapping names the GLOBAL — + // partner_code, rm_or_agent_id, source_channel. Neither is wrong; they + // are different names for the same field, and nothing between them + // reconciles it. + // + // So: exact id first, then the field's uid, then the global name with + // the suffix stripped. Accepting all three means this keeps working + // whichever convention a pipeline is authored in, rather than breaking + // again the next time one is written the other way. const pre = s.prefill_data || s.prefillData || s.field_defaults || {} if (pre && typeof pre === 'object') { const seed = {} - for (const f of s.fields) if (pre[f.id] !== undefined) seed[f.id] = pre[f.id] + for (const f of s.fields) { + const base = String(f.id ?? '').replace(/_\d+$/, '') + const v = pre[f.id] ?? pre[f.uid] ?? (base ? pre[base] : undefined) + if (v !== undefined && v !== null && v !== '') seed[f.id] = v + } if (Object.keys(seed).length) setValues(seed) } })