Read each item index of a json in Code node

Hello everyone.

I’m trying to read each item in the Loop For on Code node and have no idea how to reffer the index.

In the image i have 2 json from the previously node. Each one with a recurrency_number field and a Status Field.

I want to set a variable for each recurrency_number, when status is COMPLETE, the value will be true.

The code i’m working now:

rec1 = false;
rec2 = false;
rec3 = false;

for (const item of $input.all()) {

   if($item("0").$node["HM - Subs Purchases"].json["status"] === "APPROVED" || $item("0").$node["HM - Subs Purchases"].json["status"] === "COMPLETE")
    if($item("0").$node["HM - Subs Purchases"].json["recurrency_number"] === 1) {
      rec1 = true;
    if($item("0").$node["HM - Subs Purchases"].json["recurrency_number"] === 2) {
      rec2 = true;
    if($item("0").$node["HM - Subs Purchases"].json["recurrency_number"] === 3) {
      rec3 = true;
return  [{

I tried $item(RunIndex), $item(item) and doens’t works. &itrem(“0”) only will set the recurrency for the first json structure.

Hi @anderfesouza, welcome to the community :tada:

Are you simply looking to add fields rec1, rec2, and rec3 to your existing items, with values depending on the value of recurrency_number? You could technically do this without the code node and using the much simpler Set node instead:

This workflow would produce a result like so:

If that’s not what you have in mind, perhaps you can share the output you would like to see instead?

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