From dbbd34f7bf277f8dc6d734eb167889334461f12d Mon Sep 17 00:00:00 2001 From: Yashas Date: Mon, 7 Sep 2026 16:45:45 +0530 Subject: [PATCH] form: apply the prefill the server already sends MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Sourced By", "Submitted By" and "Source Channel" rendered empty on the new-lead form. The prefill pipeline was working the whole time — the form-screen response carries partner_code "Shetty Insurance Services (POSP-77341)" rm_or_agent_id "arjun.posp@zurichkotak.example" source_channel "agency" and the form ignored all three. The two sides key the same field differently and nothing reconciles it. A form field is the ACTIVITY key, suffixed because one global may be used on several activities in a version — partner_code_3, rm_or_agent_id_3, source_channel_4. A fieldMapping node names the GLOBAL — partner_code, rm_or_agent_id, source_channel. Neither is wrong. The seeding loop matched on f.id exactly, found nothing, and seeded nothing, with no error anywhere. Now it tries the exact id, then the field uid, then the global name with the numeric suffix stripped. Taking all three means this survives a pipeline authored in either convention rather than breaking again the next time one is written the other way. Empty and null are skipped so a mapping that resolved to nothing does not overwrite a real default. Worth noting the failure mode rather than just the fix: a prefill that matches nothing looks exactly like a prefill that was never configured. It is why the pipeline read as "empty" from the config tables — the authoritative store is tbl_wf_activity_prefill_nodes, not the pipeline_config JSONB, and the quickest honest check is neither: POST /view/form-screens and read prefill_data. --- src/components/ActivityForm.jsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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) } })