Hi I want to check a file in google drive and if the file not existed I want to create a new file. I already set a google drive node and if statement node but I don’t know how to make it works, here’s the node of the workflow:
To make the google drive works if the file doesn’t exist I need to checked “Always Output Data” on the setting tab. But if I checked this setting there isn’t any output that I can used in the if statement.
So the condition that I choose on the if statement node is “string exist” and hardcode the name of the the file that I want to search, but the output result is always true even though the file is not exist.
Anyone can tell me the wrong part in my workflow?
You’re hardcoding the string "test database" in the IF node. But the Google Drive node returns an array of files, and if no file is found, it returns an empty array.
Since your IF condition is comparing the literal string, it always evaluates to "test database" exists" which is always true.
How to fix it:
Step 1: Change the IF condition to check if any file was found
Instead of using "string exists" with a static value, do this:
In the IF node, set:
Left Value (string):
{{ $json["id"] }}
Condition: “is empty”
Connect the false output to the Create File node (because if no ID exists, the file doesn’t exist).
Connect the true output to do nothing or log that the file already exists.
When the Search File by Name node returns a file, each file will have an "id" property.
If no files match, id will be undefined or missing and your IF node will correctly detect that.
Thanks for your answer but that’s exactly where my problem lies. If I unchecked “Always Output Data” on google drive node there isn’t any id or I can use json code that you provide.
Here’s the screenshot between the “Always Output Data” on and off
From the always output data on the condition (with json code) colored red that’s why I hardcoded with the file name previously.
And if I doesn’t checked the “Always Output Data” option it will stop the workflow and that’s why I’m stuck because both option is lead to failure.