Data transformation into multiple items

Hi everyone,

I’ve been working with n8n lately and trying to build a workflow to send conversions to Facebook CAPI. The workflow is triggered by a webhook node that is connected to a form in Elementor. The data from the first step looks like this:

The second node is a SET node, as I need to filter the data I need to hash in order to send it all to Facebook. After the SET node, the data looks like this:

Now, I need to transform that item into 8 different items in order to hash them with the crypto node. So, I set up a third node, a Code node. I’m not very familiar with JavaScript, but I’ve been watching some videos from @harshil1712 on YouTube where he explains how data is structured inside n8n.

Based on those videos, the code I’m using inside the Code node is:

return items[0].json.results.map(item => ({json: item}));

But I keep getting the same error over and over:

ERROR: Cannot read properties of undefined (reading ‘map’) [Line 1]

Can anyone help me debug this script? I might be misspelling something, or maybe the code is not appropriate to separate the item into multiple items.

here’s a screenshot of the workflow so far…

Any thoughts?

Thanks in advance.


## Share the output returned by the last node

## Information on your n8n setup
- **n8n version: 0.214.3 
- **Running n8n via Docker

Hi try this,


const res = []
const item = items[0].json 

for (let key in item) {
  res.push({json:{propVal:item[key],propKey:key}})
}

return res

You may want to save the PropKey and PropValue as you will have different keys otherwise and not really sure how you could pass the data to the crypto node.

There is no results property in the item in the input node. The properties are name, email, telefono… then items[0].json.results is undefined.

2 Likes

Hello @am46,

I wanted to let you know that your code worked perfectly and I’m very grateful for your help.

Here are the steps I took right after the code node
to organize data for Facebook.

  1. Passed all items through the Crypto node.
  2. Concatenated the items back into a single item using the Item list node.
  3. Set proper names for strings that will be received on the Facebook end with a SET node
  4. Concatenated everything again and organized it under a “Data” item.
  5. Sent everything to Facebook.

This is how the workflow looks so far

On the Facebook End, the event match quality is great! meaning that all data is passing

Let’s go!:rocket::rocket::rocket:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.