> For the complete documentation index, see [llms.txt](https://doc.duaer.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.duaer.com/data/data-mapping/data-item-linking/item-linking-code-node.md).

# Preserve linking in Duaer’s Code node

In Duaer, when referencing a previous node you need to know which item to use. Most nodes link automatically; in the Code node you sometimes set pairedItem yourself.
When you have more than one incoming item and you add new items, return brand-new objects, or want to control linking yourself, set pairedItem. With a single incoming item, Duaer handles linking automatically.

## pairedItem usage example <a href="#paireditem-usage-example" id="paireditem-usage-example"></a>

Link each output to the input at the same index (indexes start at 0):

```
const newItems = [];
for (let i = 0; i < items.length; i++) {
	newItems.push({
		json: {
			name: items[i].json.name,
			aBrandNewField: "New data for item " + i,
		},
		pairedItem: i,
	});
}
return newItems;
```

## One input becomes many outputs

When one customer becomes many order items, every new item uses that same input index:

```
const out = [];
for (let i = 0; i < items.length; i++) {
	for (const order of items[i].json.orders) {
		out.push({
			json: { orderId: order.id },
			pairedItem: i,
		});
	}
}
return out;
```

## When you can omit pairedItem

With a single input item you can omit pairedItem. If you only change fields on the original items, still return one for one, and keep the existing link, automatic linking still works.
## Questions

### When must you set pairedItem?

In Duaer, when more than one item came in and you return new objects, change the count, or want to control linking. pairedItem is the source input index (from 0); one-to-many outputs share that index.

### When can you omit pairedItem?

In Duaer, when only one item came in. You can also omit it when you only change fields on the original items, still return one for one, and keep the existing link.

## Related

- [How items link across Duaer nodes](https://doc.duaer.com/data/data-mapping/data-item-linking.md)
- [Fix item linking errors in Duaer](https://doc.duaer.com/data/data-mapping/data-item-linking/item-linking-errors.md)
- [Understand Duaer’s data structure](https://doc.duaer.com/data/data-structure.md)

