Duaer

Organizations and data

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

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.

In this section