Duaer

Organizations and data

Mark item links in the Code node

When a Code node returns new items, set pairedItem on each one so later expressions know which input it came from. Without that, .item reports that the items are not linked.

Set pairedItem when one input becomes one output

When you walk the inputs in order and still return one item each, set pairedItem to that input’s index. Indexes start at 0, the same i you use in the loop.

const out = [];
for (let i = 0; i < items.length; i++) {
  out.push({
    json: { customerId: items[i].json.customerId, tier: "gold" },
    pairedItem: { item: i },
  });
}
return out;

Set pairedItem when one input becomes many outputs

One customer has many orders, and you return one item per order. Every new item came from the same input, so pairedItem uses that input index. Do not number the orders 0, 1, 2 as if each were a different input.

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: { item: i },
    });
  }
}
return out;

When a Code node can omit pairedItem

With a single input item you can omit pairedItem. Later items point back at that one item on their own. If you only change fields on the original items, still return one for one, and use a return that keeps the existing link, automatic linking still works.

As soon as the count changes, or you build a new object that dropped the old link, mark it with one of the two shapes above. Later nodes can then use .item to get back to the original customer, instead of switching to first or a hard-coded index.

Questions

When must a Duaer Code node set pairedItem?

A Duaer Code node must set pairedItem on each returned item when it returns new items and the count changed, or the new objects dropped the old link. The item value in pairedItem is the source input’s index, starting at 0. When one input becomes many outputs, every new item uses that same input index.

When can a Duaer Code node omit pairedItem?

A Duaer Code node can omit pairedItem when only one item came in. Later items then point back at that one item. It can also omit pairedItem when it only changes fields on the original items, still returns one item per input, and the return keeps the existing link.

In this section