Hi, I’m trying to use an IF node to detect empty output from a node, but I’m unable to get anything but true from it - how can I test for empty values coming out of a node?
First of all you have to know that n8n does not advance the chain if no data is available.
To avoid this, there is this setting in the respective node:
Than you can use a function to check if items are empty with:
items.length == 1 && Object.keys(items[0].json).length == 0
Here a complete example:
Can we have the complete example please?
my bad, it was ublock that hid the workflows
Thank you! I elaborated another method based on your code to very simply put this directly inside a switch as an expression, so that one can then use the boolean result to determine which way to go:
{{Object.keys($items()[0].json).length === 0}}
Hi @ArtMooney ,
Seems like what you gave might be usable for me , but I never used switch node and have trouble understanding how to use it. Hoping you can help me here please . I have to keep even the empty item enabled to keep the flow active , how ever after switch , if its empty it should be in one output which will be left unused and where as if the item is non-empty item then we need to pass it on to next node , The key here is it shouldn’t stop the flow because the item is empty.
Hello Siya,
I think you need to change the “Input type” inside your Switch node to “Boolean” for your logic to work, since you want to compare true or false statements. All the line of code does is to return a true or false based off of the incoming items stream includes items or not.
Hope this helps
Just wanted mention that there’s now an easier way: you can now do this in the if/filter/switch nodes by checking whether {{ $json }} is empty:
Either like this:
Or like this
thank you
Thank you
can we please get the node it self as a schema im struggling so much with this logic? it seems so easy and yet i cant get it right.
nvm… i got it working now idk how to rerout the convo back into a chatbot…after it knows the person
It depends on what you mean with “rerouting the conversation back into the chatbot” – if you mean that the model needs to know any changes that you make, you can use memory in an agent / assistant, and use the memory management node to insert your own interactions.
If, instead, you mean how to get a message to the chat window, by default it uses the data of the last executed node, but you can change that to use “respond to webhook” node, by changing the “Response Mode” (available from the options in the chat trigger) if you want more fine-grained control.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.