how to add validation constraints to input that must be unique

hello,

i use bonitasoft community edition v 2022.2

I have an object in my bdm named "product" that have the attribute "name" I want to add constraint to this input that must be unique, Can someone help me with groovy expression:

- How to get the object "project" with the groovy expression and search in the attribute of this object if the input value already exists?

Hi,

You can’t implement this constraint at contract level, but you can instead use a unique constraint on the Business Object:
In the BDM editor, you can navigate to the unique tab and select the name attribute for the Product object.

It will generate a query for this object that can used in a web page to validate that a given product does not already exist.
../API/bdm/businessData/com.company.model.Product?q=findByName&f=name={{product.name}}&p=0&c=1

The above query will return an empty array if the product does not exist.

If despite the UI validation, a contract is sent server side and the product name already exists, the task execution or process instantiation will fail due to the unique constraint in the BDM.

HTH
Romain