How do I prevent duplication of things with the same field value in a data type?

I’m building a simple CRM and have created 2 data types: Contacts and Companies. My Create Contact workflow on the Submit button includes one step for creating a new thing in Contacts and one for creating a new thing in Companies.

When I create two new Contacts with the same company name (Acme) in testing, I end up with two things in Contacts (yay!) and two new things in Companies, each with unique IDs but both with Company Name “Acme”. I’m unable to find any obvious way to say “only create a new thing in Companies if an existing thing with the same value in Company Name does not already exist.”

This feel like really basic functionality that I’m sure exists, but I can’t figure it out after scouring the documentation and trying lots of different approaches.

2 Likes

You can create 1 data type Companies with Fields Contacts and add button and workflow to add contacts in the existing Companie.

Comparing not unique names is not that simple as you may think.

Create a new contact

Only when

Do a search for contact

Add new constraint

Name = input contact name’s value (wherever you have this new contact name)

Add new constraint

Company name = input company name’s value (wherever the new company name is being added)

Now this search must be

:First item is empty . Thus this contact doesn’t already exist so The programs goes ahead to create the contact because it’s not a duplicate

If you want your app built fast and efficiently feel free to email me 253digital@gmail.com

3 Likes

First, thanks for the offer, but the point is for me to learn how to do this.

Second, if I’m reading your steps correctly, this approach will prevent me from creating duplicate contacts, but my challenge is to keep from creating duplicate companies. This may put me on the right path though, so thank you.

Thanks for this. I hadn’t been thinking of connecting Companies and Contacts this way, but it makes complete sense.

Success! Here’s what worked

  1. Added field Contacts (List) to Companies
  2. On Submit for create new contact
  3. Create a new company
  4. Only when
  5. Do a search for company name
  6. Add new constraint
  7. Name = input company name’s value
  8. Add to only when search…
  9. :First item is empty . Thus this company doesn’t already exist so the programs goes ahead to create the company because it’s not a duplicate

Thank you both for your help.

7 Likes

Awesome! I use the Only when do a search for first item is empty trick very often in Bubble! Hope it helps in more applications in the future too!

1 Like

How do you show some message in this case? Something like “This item exists”.
Also I noticed that when you add two constraints, the second one is not taken into account.

Yeah, This does work however a closer look at the use case (and any use case for that matter) presents more problems. The main one being is that you end up with 15 users on a CRM and now your software presumes each one of those humans will spell “Acme” and use the correct Casing 100% of the time. So Acme, acme acmi, ACME will all produce a “duplicate”

Now there are ways to also prevent this using the “contain” constraints but its not reliable and slows down the app if you do it on all fields that could be duplicated.

1 Like

It’s crazy that there’s no case insensitive way to search for duplicates before entering a new entry, “right out of the box”. It seems like a basic functionality anyone would need in order to avoid duplicates. :frowning:

I am just trying to deal with the same issue. Is there a way to do it based on the company email domain? I believe the margin of error there is smaller.

Hi, im sorry im late to reply but i might still be able to help, when you store the data, always add :lowercase to the data you are storing, that way easily check if it already exists or not