I try to use the ifempty function within an expression but the output is not what I would have expected. I need the value as output but it seems to give me ifempty as well…
I looks like you might be coming from the spreadsheet world. If not i’m curious where that syntax is from
javascript only runs inside of the {{ }} in n8n so your entire expression needs to be inside. Also, methods such as .isEmpty() go after the variable.
So you would get a true or false from .isEmpty() like this: {{ $json.code.isEmpty() }}
If you want to get a value based on that, you can use a ternarry operator like this
{{ $json.code.isEmpty() ? "value if true" : "Value if false" }}
What’s your use case here? If you want to set a default value if “code” doesn’t exist, you can use a much more concise syntax like this {{ $json.code || "default value" }}. The || means or in javascript, if the value to the left is undefined (or falsey in JS), then it will use the value to the right.
I’m coming from Integromat/make and now learning to think differnt which is not that easy if you build like that for several years
What I want is if no data get found with the value from the trigger then It goes to the loop and get another value. So in the set after the merge I want todo if value from loop set is empty then take the value from trigger. Maybe there is also a better way where I can do this but this is what I thought should work.
The workflow had a little wrong in the ifempty since I took first trigger then set. So it should be like this ifEmpty({{ $json.set2 }},{{ $json.code }})
That definitely works but you can simplify it to: {{ $json.set2 ? $json.set2 : $json.code }}
or simply it even further with {{ $json.set2 || $json.code }}.