Solving Empty String Issue in Make.com
Have you ever found yourself in a situation where you need to add a location address to a database entry, but in some cases, you only have the city name? You want to use the address if given, otherwise, you should use the city name. This is a common problem that many Make.com users face, and in this article, we will provide a step-by-step solution to this problem.
Problem
The problem arises when trying to use an if function to check for an empty string. The if function always returns the city name, even when the address is not empty. Here are some of the attempts that were made:
- Try #1: {{if(var.input.address=‘’; 2.location_city; var.input.address)}}
- Try #2: {{if(var.input.address + “=” + emptystring; 2.location_city; var.input.address)}}
- Try #3: {{if(length(var.input.address) + “=0”; 2.location_city; var.input.address)}}
Solution
The solution to this problem is to use the special keyword for checking an empty string, {{emptystring}}. However, the if function is looking for something that will give a true/false result. The way it is currently set up results in some text, which is always true.
To compare your address to emptystring, convert address to a string by using toString({{address}}) and instead of typing in the = sign you need to use {{=}}. Without the curly braces, the equal sign is being treated as text. With the curly braces, it is doing a comparison.
The final Field Value would look something like this: if(toString({{address}}){{=}}{{emptystring}};{{2.location_city}};{{address}})
Troubleshooting Tips
If you paste this into the field in Make, the curly braces will go away and should result in your actual variables. The equal sign should also turn green and look more like a variable than some text.
Conclusion
In conclusion, when checking for an empty string in Make.com, it's important to use the special keyword {{emptystring}} and ensure that your if function is set up to return a true/false result. By following these steps, you should be able to successfully use the address if given, otherwise, use the city name.
You do have further questions?
Ask your question via E-Mail: Richard@make-app.de
Book a paid Support & Consulting Session
New Make.com user? Sign up through this Affiliate Link to receive 10.000 operations for FREE.