Unique Constraints and Entity Record Counts

How do I impose unique constraints on an Entity record? Do I have to do it in my flow before I add a new record by running Query Entity?

Will adding a Get Entity Data Count activity be more efficient than querying the entities, pulling them into an IList<T> and then checking the Count?


Hi Andy, we don’t have an unique constraint yet. Currently, it has to be done by checking with Query Entity as you indicated.

I generally do the query, followed by an if condition to create new or use the existing record. Please see this example - https://docs.uipath.com/data-service/docs/using-studio-to-upload-file-fields-in-entity-records#if

Good suggestion on the just using the count instead of actually querying the data. We will add it to our backlog.


Hi Ankit,

Yes, I do query for an existing entity before I create a new one and if the IList has a count >0 then the If condition skips adding a new entity and throws an exception instead.

Similarly, my construct has the ability to use the Existing entity for the child if the parent already exists.

This works great if you are adding one parent entity as a one time thing. In my case I’m adding about 40 child Records and each record has a unique constraint that is a combination of two parents. In which case the query+check has to be performed for each child record.

For 40 records, that is 40 Select queries running against the Data Service, followed by another 40 insert queries. I was thinking if there was a unique constraint imposed, then we could try to insert the record straight away and trap the exception.

thanks for the quick response! :slight_smile:

Thanks Andy for the additional context, we definitely have Unique on our next year’s backlog and I agree that it will be much better to have.

For your context, I am not sure how complex your checks are and what your exact flow is, but will it make sense to fetch all 40 parent records once locally and then just do local checks for each child item? That way your query can perform much better.


Yep! If I have to make this a full fledged sequence, then I have to modify my flow to do this work before I start adding entity records . I was thinking more on the lines of Unit functionality where the responsibility of the Add Sequence was to check and add one single record if it doesn’t exist.