Database prevent adding existing value

Hi,

I don’t understand how it works… the comparison text I try to use is grayed out.

  1. I add a city through this form :
    add-city-field

  2. Here is the function to add the data to the DB :

  3. Here is the DB copy :

What’s wrong ?
I’d like to prevent duplicates.

  1. So I added a condition :
    cant-get-element
    But I can’t compare the Cities’name to the search ; I don’t understand how it works.

I just want to check if the city doesn’t already exists.

Thanks for your help !

Thomas

Why don’t you check if the city exists prior to DB update? Then you won’t have to deal with this problem and will be better for UX.

Thanks ! How do you that ? I haven’t been able to understand and find online how I can check if the value exists in the DB outside of the process I just described before. If you have the link to a tutorial it would help a lot

Add a text element that says “This city already exists”.
Add a workflow event “when an input’s value is changed” and in the only when area add “do a search for” the city.
Then add an action that shows the text element.
Make your button not clickable when the text element is visible.

Thanks for your feedback !

  1. I’ve created the text field
  2. I went into Workflow tab and I’ve added an event “when an input’s value is changed”
  3. I selected for “Element” the “Searchbox”
  4. Then I wanted to set up the “Only when” but I’m facing the same problem as explained at top of my post : I don’t know how to configure properly this part…

Capture d’écran 2020-08-10 à 13.43.37

So my method is :

  • “Only when”
  • “Search for Cities name” (so I imagine it returns an array ?)
  • Then I check if this array contains “This SearchBox’s value” (which is the name of the city, since when I save the city I use the same variable construction)

Thanks in advance

The 2 types you are comparing must be the same. So you’ll need to have the search for cities return text values.

Hi,

Thanks for your feedback. There are several cities in my database ; I need to compare my search with the database to see if it contains the searched city.

I can’t compare the searched city to 1 value (string) only. I should check if the db (like an array) contains it.

I don’t understand your solution of comparing same kinds of values since there is an array (db) and a text (str in search)

I’m sure my function is good. I don’t understand how it can be false. I need more help.

  1. In the “Only when” condition I have put “Search for Cities” (The Type is Cities and the constraint is “name”)
  2. Then I put “contains” and I selected “This SearchBox’s value”

So my statement is “search in the cities list if the searchbox’s value already exist as a name”. The “contains” condition is made for this kind of purpose.

Thanks in advance,

Thomas

I found the solution. Finally.

So the best seems to be this:

  1. In Workflow clicks on Click here to add an event
  2. Select the Elements > An element is clicked
  3. Then in the window select for Element the Button Validate the city
  4. Add a Only when condition which starts with Do a search for
  5. In the side window select as Type Cities ; don’t add any constraint
  6. Click on More… in the Only when and select 's name
  7. Click on More… in the Only when and select doesn’t contain
  8. Click on More… in the Only when and select SearchBox Search a city…
  9. Click on More… in the Only when and select 's value
  10. Click on More… in the Only when and select 's formatted address

Then create Steps in your workflow:

  1. Create a new City (as shown at the beginning of this FAQ post) but for name have SearchBox Search a city…'s value’s formatted address instead of SearchBox Search a city…'s value
  2. Add a clear inputs if you’d like

2 Likes

Your solution works like a charm.

The problem now is, how do I tell to the user that it hasn’t been created because it was duplicated?

Thanks!