DocEngine

Docs

Field mapping

Mapping connects an external source payload (Salesforce record JSON, ERP body, API client) to template field names using $payload… paths. It is stored on the template as fieldMapping and applied at fill or render time.

Where it lives

  • Designed in the editor Mapping UI (drag paths or edit Mapping result JSON).
  • Persisted inside template export: kind: "template" → fieldMapping.
  • Salesforce: embedded in Template_JSON__c / version snapshots.

Mapping UI

Three panes: Source payload (upload / sample JSON tree), Template fields (drag sources onto tokens), and Mapping result (editable $payload… paths, then Apply / Save).

Field mapping modal: Edit sample JSON and source tree, template fields, Mapping result with $payload autocomplete and Resolved preview values
Left: edit sample JSON + source tree. Center: drag onto template fields. Right: Mapping result ($payload… paths with autocomplete) and Resolved preview values. Save mapping stores fieldMapping on the template; Apply merges into the open document.

Spec shape

{
  "kind": "fieldMapping",
  "version": 1,
  "sourceSample": { "Name": "Acme", "CreatedDate": "2026-08-12T10:00:00.000Z" },
  "rules": [
    {
      "section": "Header",
      "field": "Customer",
      "sourcePath": "$payload.Name"
    },
    {
      "section": "Header",
      "field": "Date Added",
      "sourcePath": "$payload.CreatedDate#dd/mm/yyyy"
    }
  ]
}
  • rules — primary: section + field (+ optional childField / columnKey for tables) → sourcePath. Targets are field names, not internal ids.
  • sourceSample — design-time sample for the Mapping UI only; runtime apply uses the real payload.
  • expression — optional advanced JS with $payload (concatenation, etc.).

Avoid: mapping by fieldId; storing Mapping only on the host (it belongs on the template); paths that match the sample but not production JSON; many path hacks instead of one expression or a computed field. See JSON roles & poor shapes.

Source paths

  • Usually start with $payload: $payload.Name, $payload.Account.BillingCity, $payload.Lines (arrays for tables).
  • Date format suffix:$payload.CreatedDate#dd/mm/yyyy formats at map time (independent of the Date field’s display format).
  • Number / currency suffix: e.g. $payload.Amount#EUR:2 when needed; prefer field display format for consistency in fill + PDF.
  • Mapping result paths are single references — use a computed field or expression to concatenate.

Apply flow

// Interactive host (Salesforce / editor)
editor.setFieldMapping(template.fieldMapping);
await editor.applyFieldMapping(payload);

// Server / API link (docengine-web)
applyFieldMapping(payload, template.fieldMapping, template)
→ blocks + fieldSchemas filled for HTML/PDF

Result is a values export (or merged blocks) ready for preview/PDF. Validation can fail if required mapped values are missing or paths don’t resolve.

Salesforce: Apex buildPayload(recordId, templateId) builds the nested map from Mapping paths (SOQL for root, parents, children), then LWC calls applyFieldMapping.

n8n: either send already-shaped sections values, or enable Use Template Field Mapping with a source payload. See Examples.

Next: API & hosts · Storage & versions