# Last node never executed with SplitInBatches and If Statement

**URL:** <https://community.n8n.io/t/last-node-never-executed-with-splitinbatches-and-if-statement/3260>\
**Category:** Questions\
**Created:** [December 4, 2020, 11:53am UTC](https://community.n8n.io/t/last-node-never-executed-with-splitinbatches-and-if-statement/3260 "2020-12-04T11:53:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexsonnay](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/alexsonnay/32/2122_2.png) [@alexsonnay](https://community.n8n.io/u/alexsonnay)\
**Post date:** [December 4, 2020, 11:53am UTC](https://community.n8n.io/t/last-node-never-executed-with-splitinbatches-and-if-statement/3260/1 "2020-12-04T11:53:24Z")

</div>

Hello,

I tried SplitInBatches with Merged data at the end following the guidelines below.

SplitInBatches works. However the last node function is never executed even if the if statement returns false.

Any idea ?

```
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        0,
        360
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        400,
        480
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n {\n json: {\n url: 'https://medium.com/feed/n8n-io',\n }\n },\n {\n json: {\n url: 'https://dev.to/feed/n8n',\n }\n }\n];\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        210,
        510
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "= {{$node[\"SplitInBatches\"].context[\"currentRunIndex\"]}}",
              "value2": "= {{$node[\"SplitInBatches\"].context[\"maxRunIndex\"]}}"
            }
          ],
          "boolean": []
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        990,
        200
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\"test\"]"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1230,
        390
      ]
    },
    {
      "parameters": {
        "url": "={{$node[\"SplitInBatches\"].json[\"url\"]}}"
      },
      "name": "RSS Feed Read",
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1,
      "position": [
        760,
        400
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "RSS Feed Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RSS Feed Read": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

```

> **[Loop Over Items (Split in Batches) | n8n Docs](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.splitinbatches/)**
>
> Documentation for the Loop Over Items node in n8n, a workflow automation platform. Includes guidance on usage, and links to examples.

> [@Merging items after "split in batches"](http://community.n8n.io/t/merging-items-after-split-in-batches/1978):
>
> Hi I have a function that outputs a list of locations, which I use to look up the weather. All the data is supposed to be gathered and run through a template for rendering before going to Slack. I have a setup like this: How can I gather all the split data items into a single item?

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [December 4, 2020, 12:07pm UTC](https://community.n8n.io/t/last-node-never-executed-with-splitinbatches-and-if-statement/3260/2 "2020-12-04T12:07:44Z")

</div>

Because if there is no more data for the SplitInBatches node to return, it does not output anything anymore and the execution stops.  
So if you want it to exit after the IF-Node you should change the expression to:

```json
{{ $node["SplitInBatches1"].context["noItemsLeft"] }}

```

and change it to “boolean”.

It then exits the loop before SplitInBatches runs out of items and goes directly to the Function-Node.

---

<div class="post-metadata">

**Author:** ![alexsonnay](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/alexsonnay/32/2122_2.png) [@alexsonnay](https://community.n8n.io/u/alexsonnay)\
**Post date:** [December 4, 2020, 3:15pm UTC](https://community.n8n.io/t/last-node-never-executed-with-splitinbatches-and-if-statement/3260/4 "2020-12-04T15:15:40Z")

</div>

I tried your solution, however the result is the same unfortunately 😢

```
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        0,
        360
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        400,
        480
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n {\n json: {\n url: 'https://medium.com/feed/n8n-io',\n }\n },\n {\n json: {\n url: 'https://dev.to/feed/n8n',\n }\n }\n];\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        210,
        510
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [],
          "boolean": [
            {
              "value1": "= {{$node[\"SplitInBatches\"].context[\"noItemsLeft\"]}}",
              "value2": true
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        990,
        200
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{\"json\": {\"item\": \"test\"}}]"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1230,
        390
      ]
    },
    {
      "parameters": {
        "url": "={{$node[\"SplitInBatches\"].json[\"url\"]}}"
      },
      "name": "RSS Feed Read",
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1,
      "position": [
        760,
        400
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "RSS Feed Read",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RSS Feed Read": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![alexsonnay](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/alexsonnay/32/2122_2.png) [@alexsonnay](https://community.n8n.io/u/alexsonnay)\
**Post date:** [December 4, 2020, 4:29pm UTC](https://community.n8n.io/t/last-node-never-executed-with-splitinbatches-and-if-statement/3260/5 "2020-12-04T16:29:14Z")

</div>

My bad I didn’t setup the If module the right way. Thanks @jan !

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [December 4, 2020, 5:55pm UTC](https://community.n8n.io/t/last-node-never-executed-with-splitinbatches-and-if-statement/3260/6 "2020-12-04T17:55:09Z")

</div>

Great to hear that it works now. Have fun!
