IF/ELSE Steatment inside Expressions (Set Node)

Describe the problem/error/question

I’m trying to use else condition in set nodes (expressions) i’ve about 40 items, so the best way to achieve this is using the expression ineasted of ~40 copies of IF/SET nodes.

The issue is I tried to do this using Add else Condition in IF nodes Expression solution and using Add else Condition in IF nodes Expression - #4 by sirdavidoff. solution, both not working with my expressions:

Current expression: {{ $evaluateExpression($('Split').item.json[\"modifiedTags\"].join(', ')) ? $evaluateExpression($('Split').item.json[\"modifiedTags\"].join(', ')) : $('Parsing').item.json[\"HiddenData\"].match(/internal_product_tags:\\[\"(.*?)\\\"]/)[1] }}

What I want:
If this {{ $evaluateExpression($('Split').item.json["modifiedTags"].join(', ')) }} undefined, then output this: {{ $('Parsing').item.json["HiddenData"].match(/internal_product_tags:\["(.*?)\"]/)[1] }} And if both had value, then output the first one only.

What is the error message (if any)?

Getting undefined when there’s a value in the second expression in this case which is cross-sale:

Please share your workflow

Information on your n8n setup

  • **n8n version: latest
  • **Database (default: SQLite):default
  • **n8n EXECUTIONS_PROCESS setting (default: own, main):default
  • **Running n8n via (Docker, npm, n8n cloud, desktop app):Docker/hetzner
  • **Operating system:ubuntu

Hi @anas :wave:

Would you be able to provide some sample data as well in JSON format? Your set nodes are still referencing previous nodes, and it’d be helpful to see the full context of what data you’re working with.

1 Like

@EmeraldHerald Sure, but the code is too long to paste here, so I uploaded it to Gist: https://gist.githubusercontent.com/ARHAEEM/e3d0835a1db07302a75e5c6e280c8665/raw/829f2b0a16b499a4a8df5da22012ac31e6b7a428/umimJV0gfQ.txt

The reason for using two expression is sometimes the internal_product_tags value is (Variable) like: internal_product_tags:x,s,a,d and sometimes it can be a value like internal_product_tags:["Cross-sell"]. so the first expression to get the value of variables, and the second expression to get the value without virable. Both can’t work in same expression, even when use ?: method.

Hey @anas,

Is that a web page you are trying to scrape? There is a lot in the gist so it would be handy to know which node it is coming from, It might be easier to share the full workflow.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.