Hi!
I’m trying to build a workflow that involves setting the value of a variable based on some conditions. I have seen some previous posts like:
…and while they cover my question, I’m hoping to see if there’s a different solution than the ones I know or are proposed there.
What I’m looking for is basically an equivalent of:
// returning an object as n8n needs an object to be returned as far as I'm aware
switch (sp) {
case 100001:
return {
l: 'string-1'
}
case: 100000:
return {
l: 'string-2'
}
// ... and so on
}
I am aware that the Code node can easily achieve this and that’s what I currently have, but my team is trying to have minimal dependency on the Code node for 2 reasons:
- we want to have a no to low-code automation as much as possible. Yes, the above code does fall in the “low-code” category, but I figured I could ask if there’s a way to even further minimize it.
- debugging the Code node as compared to a Switch node is a bit difficult because the Switch node highlights the exact condition and route the workflow took, which the Code node does not do. So with the Switch node, we can visually inspect what route the workflow took and then figure out why it might have done that.
When the above is translated to a Switch node, the workflow looks something like:
As you can see it looks really complicated. In my case that’s not even the complete workflow, so the n8n UI gets fairly laggy and the readability is completely lost. I had to trim down my condition count to upload the workflow in the editor. I have about 21-22 conditions in total.
Do I have any better options here?
