Data Restoration Using itemMatching() in Code Node - n8n Workflow

Master advanced n8n workflow techniques. This n8n template shows how to use the itemMatching() function in a Python code n8n node to restore original data fields after preceding data transformations.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

This automation is ideal for:
n8n developers learning advanced scripting techniques.
Users needing reliable methods to preserve data lineage across complex n8n workflows.
Engineers building modular n8n templates where item indices must be maintained for data correlation.
Anyone seeking a deeper understanding of data manipulation within the n8n execution context.

Overview

When building complex n8n workflows, you often need to transform or filter data streams, which can sometimes result in the temporary loss of original fields (like emails or IDs). This specific n8n workflow provides a robust solution using the built-in itemMatching() function available within the Code n8n node.

The value of this n8n automation is in ensuring data integrity. It simulates a scenario where initial data is generated, then aggressively pruned (keeping only names), and finally, the original email address is accurately retrieved and restored using item index correlation. This approach is vital for advanced data manipulation and demonstrates one of the most powerful features available in the n8n scripting environment for linking data items across different stages of the n8n workflow.

How it Works

This n8n workflow operates in four distinct phases:


  1. Initiation (Manual Trigger): The n8n trigger starts the process when the user clicks 'Execute Workflow'.

  2. Data Generation: The Customer Datastore (n8n training) n8n node generates a list of sample customer records, including names and email addresses. This establishes the initial data stream.

  3. Data Reduction: The Edit Fields (Set) n8n node intentionally strips away all fields except the customer name. This simulates a common scenario where data is streamlined, and the original context is seemingly lost.

  4. Data Restoration (Code Node): The final n8n node, a Python Code node, executes the core logic. It iterates through the reduced data items. For each item, it uses the itemMatching(i) method, referencing the original data output from the 'Customer Datastore' n8n node, to retrieve the corresponding email address based on the index i. This retrieved email is then appended back to the current item under a new field called restoreEmail. This powerful technique ensures data consistency throughout the n8n workflow.

Installation Guide

To deploy this n8n template, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON code.

  2. Open your n8n instance and navigate to the 'Workflows' section.

  3. Click 'New' or 'Import from JSON' and paste the code.

  4. Execute: Since this n8n workflow uses a manual n8n trigger and mock data nodes (for training purposes), no external credentials are required.

  5. Click the 'Execute Workflow' button on the 'When clicking "Execute Workflow"' n8n node to see the item matching logic in action. Review the output of the final Code n8n node to confirm the email addresses were successfully restored.

Node Details

This n8n workflow leverages the following key n8n node types:

When clicking "Execute Workflow" (Manual Trigger):
Function: Acts as the starting n8n trigger for testing and development.
Key Configuration: No configuration required; starts the n8n workflow on demand.

Customer Datastore (n8n training):
Function: Generates sample data (customers with names and emails) to provide a source data stream.
Key Configuration: Operation set to getAllPeople, with returnAll checked.

Edit Fields (Set):
Function: This n8n node performs a data transformation, reducing the incoming items to only retain the 'name' field. This simulates the data loss scenario we intend to fix.
Key Configuration: Includes only the name field, setting the input option to none to discard all other fields.

Code (Python):
Function: The critical n8n node where the itemMatching() method is used. It correlates the current item index with the original index from the 'Customer Datastore' to pull the original email.
Key Configuration: Uses Python logic:

for i,item in enumerate(input.all()):
input.all()[i].json.restoreEmail = ('Customer Datastore (n8n training)').itemMatching(i).json.email
return
input.all();
This demonstrates how powerful custom scripting can be in an n8n workflow.

Related n8n Workflows

Free

Nodes: 0 Nodes
Updated: December 26 2025
View all
Created by
n8n Team
n8n Team

Meet the official n8n team. We specialize in building workflows that transform intricate tasks into seamless operations.

Featured*