Fold Source Fields Before Merge: Self-Contained Items Without pairedItem Expressions
Loading workflow…
Workflow Description
A fully local n8n template. A manual trigger feeds two branches whose Code nodes emit fictional order and payment items. Folding Code nodes copy every field later stages need into the item itself using _a_ and _b_ prefixes, normalise strings and numbers, and compute _fold_missing plus _fold_complete. Set nodes pin _fold_version while keeping other fields. A Merge in append mode joins the branches, an IF routes complete items to a self-check node and incomplete ones to a NoOp, and a second Merge rejoins both routes into one final Code node that flattens each item and labels it complete or quarantined. No credentials, no external calls, no upstream references after the merge.
How it works
- 1.Manual trigger emits an empty item into both branch paths
- 2.Two Code nodes generate demo items shaped {order, payer}, one with an invalid payer value
- 3.Fold nodes copy order.id, amount, currency, payer.name, payer.method into _a_* and _b_* with type normalisation
- 4.Each fold node computes _fold_missing, _fold_complete and the _src branch tag
- 5.Set nodes add _fold_version with includeOtherFields enabled
- 6.Merge in append mode combines both branches into one stream
- 7.IF checks _fold_complete with strict type validation: true to the self check, false to the NoOp quarantine
- 8.A second Merge rejoins both routes and the final Code node flattens fields, emitting status and missing_fields per item
Use cases
- Stabilising flows where $('NodeName').item broke after a merge node
- Unifying order and payment records from two different sources
- Flagging records with missing fields separately from valid ones
- Auditing merged data quality before export
Requirements
- n8n 2.46.4 or a build with equivalent merge behaviour
- A decided list of fields needed later before editing the fold nodes
- Replace the two sample Code nodes with real sources using the same {order, payer} schema
- Never use $('NodeName').item after the merge node
Setup and testing in n8n
- Import the JSON and click Execute Workflow
- Confirm Build Final Records outputs four records: three complete and one quarantined
- Confirm ORD-1003 has status=quarantined with missing_fields containing _b_payerName and _b_payerMethod
- Swap the branch wiring between merge inputs 0 and 1 and confirm the same record set
- Set one sample array to empty and confirm the run finishes without error
Service Value
Ready-made workflow template for automation delivery and service execution.
Apps Used
Details
How to Use
- 1.Click "Download Template"
- 2.Open your n8n dashboard
- 3.Go to Workflows > Import from File
- 4.Select downloaded file and configure credentials
Nodes Used (13)
Manual Trigger
Manual Trigger
Sample Branch A Orders
Code
Fold Source Fields Branch A
Code
Pin Folded Fields A
Set
Sample Branch B Payments
Code
Fold Source Fields Branch B
Code
Pin Folded Fields B
Set
Merge Branches Append
Merge
If Folded Fields Complete
If
Self Check Folded Items
Code
Quarantine Incomplete Items
No Op
Merge Verified And Quarantined
Merge
Build Final Records
Code
Note Branch Setup
Sticky Note
Note Architecture Rule
Sticky Note
Note Routing And Output
Sticky Note
Fresh workflows, straight to your inbox
Get newly published DROPIDEA workflows, a clear overview of what they do, and a link to explore them.
- New workflows
- Clear overviews
- Setup guides