How write expression in event handler that data should be unique

Good Day Mendix Expert,   I would like to ask how you write expression for event handler that data should be unique? I cannot put the data as unique in the domain because a number of user have same date or data. I would like to prevent duplicate data on the current user. how should I do that in the event handler-domain?
3 answers

Hi Frederick,

to guide you to the exact check you can use, we'll need more information about the domein model.

If the use case is that the user can't select the same date for a reservation. I assume the user is already connected to another reservation? A check like this will probably suffice. 

If true, there is no duplicate date found and the user can be added to the reservation. 

If false, you can show a message to the user.



If you really want to do it in event handler, you must probably add couple of events like before create and before commit

In the microflow, pass the object of the entity, with in the microflow use the $currentUser and other unique validation criteria that is applicable. Return false if the validation fails


You could do a retrieve on the variable that you want to be unique, to see if there are any objects already in existance. If none exist, the data is unique and you can create the object, if not, you can return the object you retrieved. But like Roy said we’d have to know more to be more specific. 

Also, please reconsider using event handlers, they are considered bad practice and should pretty much never be used!!