Preventing duplicates when adding to a collection

I’ve seen another post on preventing duplicate data creation here (Prevent from create duplicate data?). The solution suggested is to add a constraint at the event condition level.

However let’s say you have a really long flow of actions (only one of which is to add a new thing) - that would mean that you need to maintain that set of actions twice in every case where you want to prevent duplicate data from being added. That can become a pain if you make changes to an action or set of actions because you now always need to do it twice.

Instead, what I’ve been doing to prevent adding duplicates is to rather just use “Make changes to thing…” instead of “Create a new thing…” and select the “Create if doesn’t exist” option.

However, where that is breaking down for me is when I need to add something to a collection - because typically the collection is on an object. So if you select the “Create if doesn’t exist” option it will apply that to the base object rather than the collection. What I want is for the “Create if doesn’t exist” option to apply when adding to the collection so that I don’t add a duplicate to the collection.

Any suggestions on how I should be doing this?

maybe creating a Custom Event with a condition would help?

1 Like

Yes, as above, you can do it all once in a custom event.

Alternatively can you prevent it happening at field level ? i.e. whatever the “key” you consider makes it a duplicate, can you prevent the user from selecting it ?

Interesting. Please elaborate on how you would do this with a custom event?

Re doing it at field level - do you mean constraining it in the database, and if so how do you do that? I don’t see that option when creating a field.

@NigelG I’m still not clear on the solution here?

Custom events allow you to re-use logic. I don’t know how preventing duplicates from being added to a collection would be possible even with a normal event.

Doing it at a data level sounds interesting but I don’t see any options on the data side to have any constraints like that.

You were talking about a long series of actions that would need to be repeated, so one way of getting round this would be to set up a custom event, so that you can reuse and copy.

Oh I see what you mean, that makes sense wrt the actions. However preventing duplicates from being added on a collection still seems like quite a challenge to me.

Let’s say you had Students with a collection of Teachers and a collection of Classes. If there’s an event that needs to add a Class and a Teacher to a student. And for the sake of argument they have to be combined into a single event (the example is just for the purpose of getting an understanding of the right approach)…

What I understand is that in order to prevent duplicates being added you would technically need 4 versions of the event all with different combinations of conditions:

  1. Event Student is updated and Teacher already exists in Student’s teachers and Class doesn’t exist in Student’s classes.
    -> Actions: Only add the Class
  2. Event Student is updated and Class already exists in Student’s classes and Teacher doesn’t exist in Student’s teachers
    -> Actions: Only add the Teacher
  3. Event Student is updated and Class already exists in Student’s classes and Teacher already exists in Student’s teachers
    -> Actions: Do nothing
  4. Event Student is update and Class doesn’t exist in Student’s calsses and Teacher doesn’t exist in Student’s teachers
    -> Actions: Add the Class and add the Teacher

This just doesn’t seem like a good approach and would make an app like this incredibly difficult to maintain (not to mention that if you had a third collection you would now need 9 combinations of the event).

I was hoping there would be a way to address the duplication at the action level (like you would with a single item where you could just use Action: Change and Create if item doesn’t exist) but I can’t seem to find a way to do that.

Am I missing something in terms of the capability of the platform?

Ah, ok, so that is fairly easy. You would use the :plus function on each list, and it would prevent duplicates in the list. So update Student’s List of Classes = Student;s List of Classes : plus Selected Class.

What I wasn’t getting was preventing a duplicate LIST item rather than a duplicate THING.

So adding another teacher called “Anne Teacher” for example.

1 Like

Great, will give that a try. Thanks!

So if a user had a list of email addresses for example, I would ‘Make changes to a list of things’ (being email address) like so?

“Make Changes to a List” and making “changes to a thing” with a list are not the same thing, but do get confusing.

If you had a list on a user, you would need to make changes to the user, and manipulate the list (add, remove, set list etc).

Making changes to a list, as above, makes the SAME change to every email address in the list.

If I get it correctly:

if they have X’s Y, where Y is a list of SomeType,

instead of using
Add to List X’s Y
the SomeTypedThing

they should use
Make changes to object X
Y = Y:plus SomeTypedThing

How come there isn’t a checkbox at Add to List action then to not add duplicates?

If you make changes to a Thing rather than a list of things, you have to select ‘Change another value’ in order to update the list. There’s no ‘plus’ option when you select the list of things that you want to add to, only the following options.

Is Set List (to itself) plus the new item the right way to go about this? If I do that it doesn’t seem to be adding the new item to the list.