IF Node - Any option to have Multiple Output conditions (CASE statement)?

I’ve a demo workflow which contains few fruits and their color. So currently I’m putting multiple IF nodes to separate them and do action afterwards. Looking for something similar to CASE statement

So rather than using N number of IF nodes, any elegant way to do this activity? (Or is it a feature request to have a CASE node)
My requirement is something of below screenshot, if that’s possible?

Sample Code Attached below

	
name	"My workflow 3"
nodes	
0	
parameters	{}
name	"Start"
type	"n8n-nodes-base.start"
typeVersion	1
position	
0	240
1	300
1	
parameters	
functionCode	"return [\n  {\n    json: {\n      name: \"apple\",\n      color: \"red\"\n    }\n  },\n  {\n    json: {\n      name: \"strawberry\",\n      color: \"red\"\n    }\n  },\n  {\n    json: {\n      name: \"pear\",\n      color: \"green\"\n    }\n  },\n    {\n    json: {\n      name: \"orange\",\n      color: \"orange\"\n    }\n  }\n]"
name	"Function"
type	"n8n-nodes-base.function"
typeVersion	1
position	
0	420
1	300
notesInFlow	true
notes	"Mockup data"
2	
parameters	
conditions	
boolean	[]
string	
0	
value1	"={{$json[\"color\"]}}"
value2	"red"
name	"IF_RED"
type	"n8n-nodes-base.if"
typeVersion	1
position	
0	680
1	80
3	
parameters	
options	{}
name	"RED_ACTION"
type	"n8n-nodes-base.set"
typeVersion	1
position	
0	940
1	60
4	
parameters	
conditions	
boolean	[]
string	
0	
value1	"={{$json[\"color\"]}}"
value2	"green"
name	"IF_GREEN"
type	"n8n-nodes-base.if"
typeVersion	1
position	
0	680
1	260
5	
parameters	
conditions	
boolean	[]
string	
0	
value1	"={{$json[\"color\"]}}"
value2	"orange"
name	"IF_ORANGE"
type	"n8n-nodes-base.if"
typeVersion	1
position	
0	680
1	420
6	
parameters	
options	{}
name	"ORANGE_ACTION2"
type	"n8n-nodes-base.set"
typeVersion	1
position	
0	940
1	400
7	
parameters	
options	{}
name	"GREEN_ACTION"
type	"n8n-nodes-base.set"
typeVersion	1
position	
0	940
1	240
connections	
Function	
main	
0	
0	
node	"IF_RED"
type	"main"
index	0
1	
node	"IF_GREEN"
type	"main"
index	0
2	
node	"IF_ORANGE"
type	"main"
index	0
Start	
main	
0	
0	
node	"Function"
type	"main"
index	0
IF_RED	
main	
0	
0	
node	"RED_ACTION"
type	"main"
index	0
IF_GREEN	
main	
0	
0	
node	"GREEN_ACTION"
type	"main"
index	0
IF_ORANGE	
main	
0	
0	
node	"ORANGE_ACTION2"
type	"main"
index	0
active	false
settings	{}
id	8

Hi @getk, your example code doesn’t seem to contain valid JSON so I am unfortunately not able to run it. But from the sounds of it you’re looking for the Switch node.

Example Workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "dataType": "string",
        "value1": "={{$json[\"action\"]}}",
        "rules": {
          "rules": [
            {
              "value2": "red"
            },
            {
              "value2": "green",
              "output": 1
            },
            {
              "value2": "orange",
              "output": 2
            }
          ]
        },
        "fallbackOutput": 3
      },
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Green Output",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        900,
        200
      ]
    },
    {
      "parameters": {},
      "name": "Red Output",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        900,
        0
      ]
    },
    {
      "parameters": {},
      "name": "Orange Output",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        900,
        400
      ]
    },
    {
      "parameters": {},
      "name": "Other Output",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        900,
        600
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "action",
              "value": "orange"
            }
          ]
        },
        "options": {}
      },
      "name": "Set Example Item",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set Example Item",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Red Output",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Green Output",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Orange Output",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Other Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Example Item": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Let me know if that’s what you had in mind or if I missed anything here :slight_smile:

1 Like