Null output

Hi everybody

In my case:

  • I want to add an ID to new row in google sheet.
  • I generate a random ID by “function” node.
  • search my table in google sheet to find that I have that generated id or not by google sheet" node.
  • if there isn’t that id I create new row with that random id.

my problem is:
after search my table in google sheet (by lookout in google sheet node) how can I use null output in “if” node.
How can I use something like this:
if search results = 0 then true

Update:
I think One Option is add “empty” and “not empty” in string in “if” node.

Sorry to hear that you have problems!

Checking for an empty item is possible like this:

1 Like

Thank you @jan
Is this just for strings or I can use it for numbers too?

Should work for everything. All the expression does is to check if the item returned from the node contains any data.

1 Like

I have the following:
{{!!Object.keys($node["Get User"].data).length}}
where Get User, is a MySQL query that returns 0 rows.

On the Result (UI) it always says [not found]. Indead, if the query returns no results, the attribute data does not get created. Is there a way to check if data attribute exists?
Or, what’s the best solution to test if no rows where returned?

Thank you!

If the MySQL query does not return any rows the node after it does not executed as nodes only get executed if there is data. If you want that the next node does get executed no matter what, you can activate the option “Always Output Data” under the “Nodes” tab (next to the “Parameters” tab). Then it will make sure that at least always an empty object does get returned. Then also the above expression should work again.

1 Like

Thank you!

This worked like a charm.
All I had to do was to activate that option. I didn’t know it existed, sorry, still new here:)

Thanks for the help.

All good. Most people do not and is very hidden. For sure more our fault than yours.

No worries!

But perhaps you can consider changing the tab label. Something like “Node settings” or just “Settings”.

1 Like

Sorry totally forgot to update here. Got renamed to “Settings” a while ago.

Hello,

I test n8n which I find very good.
I want to create a workflow to search if a value exists in my google sheets (I use lookup) and if so, do nothing, otherwise add the value.

I have a problem with the “if” function. If I activate the option “always output data”, and put {{!!Object.keys($node["Google Sheets"].data).length}} into value 1, only the true branch is always activated.

Do you have a solution?

Best regards

Hey @jeanguy!

Welcome to the community :slightly_smiling_face:

In the IF node, you can select the branch for which you want to see the output. By default, it displays the output for the true branch. You can change it to false by select false from the Output dropdown list on the top of the node.

If the false branch is still not giving an output, please share your workflow so that I can replicate it.

Hope this helps.

Thank you @harshil1712
I don’t know how execute the false branch, when value is not in google sheets.

Please find me screen:

If the value didn’t exist in google sheets, IF result is “not found” and no nod is executed.
If I check “always output data” it is the true branch wich is executed.

How does your IF-Node look like? Can you please post a screenshot.

In this case, you should not set “Always Output Data”. As it does exactly what you describe. It will always output data to the true-branch if there is nothing for the false one. As that is not helpful in this case, there is no need to set it.

This is my If node:

Here an example workflow with the data from the Google Sheets node mocked:

To test how it would work if data would be found you can simply remove the // in the Function-Node.

Having now looked into what you want to do some more you would have to activate the option “Always Output Data” but not on the IF-Node, you have to activate it on the Google Sheets node. Because if you do not set it, and no value would be found the execution would stop at the Google Sheets Node.

Thank you very much, its works, even without node function.
To be sure I understand, when value don’t exists in google sheet, outbut data is empty, and IF node test if google sheets node has data?

So what is the role of the node function?

The Function node is just used for the example. It is not required in your use case.

Ok, thank you.