Problem: can’t put in all cities in the world as a database, as that will be too large and slow when picking in a form.
So I’ve set up a location field, and then it makes the city entity if it doesn’t exist, and links the right city if it does exist. The bug is that sometimes it creates a new city even though the city already exists.
Not sure I fully understand what is going on, nor how it is supposed to work, but by guess is that your formula field (which is asynchronously updated) is not giving the correct city name at the time the first automation runs, meaning that your automation formula is trying to find a city in the database with the name ‘Invalid City’. This then means the last automation is running, and new city is being added.
Just a hunch.
Check if this city already exists by trying to link it to the City Field
4.1 It exists? Just uncheck the box
4.2 Doesn’t exist? Create it, link it, then uncheck the box.
The problem isnt that its making a city with “Invalid name”, it’s making duplicate cities. Even though Amsterdam already exists, it creates it and links it. I really don’t know why. When i test it seems to be working, but then every now and then it creates more cities! Any ideas im really lost..
Automation #1 triggers, and it wants to updates the City relation field, but at the time it runs, the City Name formula field has not been calculated (= “Invalid City”) so City field stays empty (there is no City entity to match an empty value this name).
Automation #3 therefore triggers, due to checkbox getting set by automation #1, and because City field is empty and City Name field is not empty. A new City entity is now created (not with the name “Invalid City”, but with whatever is the ‘place’ part of the Location field), even though there probably already was a city that should have matched the (eventually calculated) City Name.
There is no determinism in your automations to guarantee that the formula which gets the City Name will execute before the automation #1 action executes.
The thing is, I have a city called “Invalid City” that should be linking then in this situation, but isn’t.
But i see what you mean that it’s using the city name, even thought thats updated after the Location. I changed the initial rule to run on “city name” update. Lets see if it works now. Thanks!
Aaah okay yeah this makes sense. Even though the formula field is static, it needs to request the value from the formula engine, which happens only after the entity is created. Okay thanks. I will update in a few days after some data is created. For some reason when I test it, it always works. Maybe different latency from the formula engine? No idea.