Force end workflow

Hello!
I have a structured workflow, which is a sequence of smaller tasks.
My main workflow looks like this:

This how one of tasks looks like:

So, I want the main workflow to end it’s execution at some points of tasks (showed on the picture).
Any option how I can force end the main workflow based on tasks execution result (except sequence of IFs)?

Hi @Dmytro_Biletskyi , an idea to reach your goal, is using the Function node to return an empty items array, that way the next node (either an execute workflow node or other) will not execute.

The same idea applies when the last node of a subworkflow return 0 items, then the next node in the main workflow will stop.

for example; this main workflow, using a mock data first, then executing a workflow (that will always return an empty array items)

Executing this main workflow will always stop in the second node, because there is no more items to use in the 3rd one.
Workflow json:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "source": "parameter",
        "workflowJson": "{\n  \"nodes\": [\n    {\n      \"parameters\": {\n        \"conditions\": {\n          \"boolean\": [\n            {\n              \"value1\": true\n            }\n          ]\n        }\n      },\n      \"name\": \"IF\",\n      \"type\": \"n8n-nodes-base.if\",\n      \"typeVersion\": 1,\n      \"position\": [\n        500,\n        300\n      ]\n    },\n    {\n      \"parameters\": {},\n      \"name\": \"Start\",\n      \"type\": \"n8n-nodes-base.start\",\n      \"typeVersion\": 1,\n      \"position\": [\n        250,\n        300\n      ]\n    },\n    {\n      \"parameters\": {\n        \"conditions\": {\n          \"boolean\": [\n            {\n              \"value1\": true\n            }\n          ]\n        }\n      },\n      \"name\": \"IF\",\n      \"type\": \"n8n-nodes-base.if\",\n      \"typeVersion\": 1,\n      \"position\": [\n        500,\n        300\n      ]\n    },\n    {\n      \"parameters\": {\n        \"url\": \"test\",\n        \"options\": {}\n      },\n      \"name\": \"HTTP Request\",\n      \"type\": \"n8n-nodes-base.httpRequest\",\n      \"typeVersion\": 1,\n      \"position\": [\n        750,\n        190\n      ],\n      \"notesInFlow\": true,\n      \"notes\": \"Some action\"\n    },\n    {\n      \"parameters\": {\n        \"functionCode\": \"// return 0 items to stop execution flow\\nitems = [];\\nreturn items;\"\n      },\n      \"name\": \"Function\",\n      \"type\": \"n8n-nodes-base.function\",\n      \"typeVersion\": 1,\n      \"position\": [\n        750,\n        350\n      ],\n      \"notes\": \"Return emty items array\"\n    }\n  ],\n  \"connections\": {\n    \"IF\": {\n      \"main\": [\n        [\n          {\n            \"node\": \"HTTP Request\",\n            \"type\": \"main\",\n            \"index\": 0\n          }\n        ],\n        [\n          {\n            \"node\": \"Function\",\n            \"type\": \"main\",\n            \"index\": 0\n          }\n        ]\n      ]\n    },\n    \"Start\": {\n      \"main\": [\n        [\n          {\n            \"node\": \"IF\",\n            \"type\": \"main\",\n            \"index\": 0\n          }\n        ]\n      ]\n    }\n  }\n}\n"
      },
      "name": "Execute Workflow",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1,
      "position": [
        600,
        300
      ]
    },
    {
      "parameters": {
        "workflowId": "34"
      },
      "name": "Execute Workflow1",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1,
      "position": [
        800,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        420,
        300
      ],
      "notesInFlow": true,
      "notes": "Add mock items"
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Workflow": {
      "main": [
        [
          {
            "node": "Execute Workflow1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Execute Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

The workflow used in the second node

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": true
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "url": "test",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        750,
        190
      ],
      "notesInFlow": true,
      "notes": "Some action"
    },
    {
      "parameters": {
        "functionCode": "// return 0 items to stop execution flow\nitems = [];\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        750,
        350
      ],
      "notesInFlow": true,
      "notes": "Return emty items array"
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Please give it a try and let me know if it helps.

1 Like

Hey @Dmytro_Biletskyi!

Did the above solution resolve your issue? Do let us know if you still need help :slight_smile: