Error while trying to loop to get every items from my Monday.com boards

Hello,

I’m trying to get all items from all of my boards with the Monday node. For this, I have a first Monday Node to get all my boards. Then, I have another one to get all groups for each board. At this point, everything is fine. But when I want to get every items for each group, it only returns items from the first group.

I used the SplitInBatches Node because I need to reuse the Board ID from the first Node for the two other.

Here’s the output of the “Get all groups” Node:
image

Here’s the output of the “Get all items” Node:

I only get the items from the “Active Projects” group but not for the “Finished Projects” one and instead I get an error saying “Cannot read property ‘length’ of undefined”.

Do you have any clues how to fix this ?

Hey @Madriax,

Can you please share the workflow? Please replace any sensitive data with dummy data :slight_smile:

Hi @harshil1712,
Here is the workflow. (All the data you see on the screenshots are already dummy data!)

{
    "nodes": [
      {
        "parameters": {},
        "name": "Start",
        "type": "n8n-nodes-base.start",
        "typeVersion": 1,
        "position": [
          300,
          300
        ]
      },
      {
        "parameters": {
          "batchSize": 1,
          "options": {}
        },
        "name": "SplitInBatches",
        "type": "n8n-nodes-base.splitInBatches",
        "typeVersion": 1,
        "position": [
          730,
          300
        ]
      },
      {
        "parameters": {
          "operation": "getAll",
          "returnAll": true
        },
        "name": "Get all boards",
        "type": "n8n-nodes-base.mondayCom",
        "typeVersion": 1,
        "position": [
          530,
          300
        ],
        "credentials": {
          "mondayComApi": "Monday test acc"
        }
      },
      {
        "parameters": {
          "resource": "boardGroup",
          "operation": "getAll",
          "boardId": "={{$json[\"id\"]}}"
        },
        "name": "Get all groups",
        "type": "n8n-nodes-base.mondayCom",
        "typeVersion": 1,
        "position": [
          880,
          460
        ],
        "credentials": {
          "mondayComApi": "Monday test acc"
        }
      },
      {
        "parameters": {
          "resource": "boardItem",
          "operation": "getAll",
          "boardId": "={{$node[\"SplitInBatches\"].json[\"id\"]}}",
          "groupId": "={{$json[\"id\"]}}",
          "returnAll": true
        },
        "name": "Get all items",
        "type": "n8n-nodes-base.mondayCom",
        "typeVersion": 1,
        "position": [
          1090,
          460
        ],
        "credentials": {
          "mondayComApi": "Monday test acc"
        },
        "continueOnFail": true
      }
    ],
    "connections": {
      "Start": {
        "main": [
          [
            {
              "node": "Get all boards",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "SplitInBatches": {
        "main": [
          [
            {
              "node": "Get all groups",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Get all boards": {
        "main": [
          [
            {
              "node": "SplitInBatches",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Get all groups": {
        "main": [
          [
            {
              "node": "Get all items",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Get all items": {
        "main": [
          [
            {
              "node": "SplitInBatches",
              "type": "main",
              "index": 0
            }
          ]
        ]
      }
    }
  }

Hey @Madriax,

In the Get all items node, can you try the following expression: {{$item("0").$node["SplitInBatches"].json["id"]}} :slight_smile:

1 Like

@harshil1712 ,
It works, thank you very much !

I can’t figure out why we need to add $item("0") tho, could you explain it please ?

Hey @Madriax,

Sure! The Get all groups node is returning 2 items, while the Split In Batches node is returning only one item (one item for each batch). For every new iteration, the Get all items node uses a new item. Now, since we have only one Board ID and two different groups, the node gives an error. With $item("0") we ask the node to refer to the same Board ID for different groups.

Let me know if you need more explanation :slight_smile:

1 Like

@harshil1712 Ok now I understand :slight_smile:
Thank you so much for helping me and taking time to explain it here !

1 Like

Wonderful! I hope this helps you further too!

Have fun :tada:

1 Like

I do not think you need the splitbatches node there. n8n automatically over the input items. I think you can simplify the workflow by removing the splitbatches node.

Hi @RicardoE105

When I remove the splitbatches node, I ran into the same problem again. And I can’t use @harshil1712 solution because $item("0") would now only return the first board id, and I have multiple ones.