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