unique validation rule over more than one attribute

2
Is there a way to specify a unique validation rule over more than one attribute? If not, will it be possible in the future?
asked
2 answers
2

It's not possible to specify this in the domain model. You can however enforce this using a before commit event on the entity containing the those attributes.

answered
0

I assume you mean that if you have attributes A and B, the values should be unique across the attributes? (So if attribute A on an object has a certain value, attributes A and B are not allowed to ever have this value) I don't think this is supported through validation rules you can define for an entity.

For now you could work around it with a before commit microflow on the object(s) containing the attributes which should remain unique. Then for these attributes you could try a retrieve activity which tries to retrieve objects which have an identical value (to the one being assigned) for the attributes which should be unique. If no objects are returned things are fine and you can have the microflow return 'true', whereas if one or more objects are returned with the value you are trying to assign to the attribute, that means the uniqueness requirement is violated and the before commit microflow should return 'false'. (I'd also recommend adding validation feedback in case this happens, so it's clear what the issue is)

One minor thing you might encounter if you are comparing strings is that the unique validation rule on an entity will do a check which is case-insensitive, whereas if you try a retrieve activity as described above, the comparison is case sensitive. You could work around this by using a toLowerCase(X) function for both the values being compared. (So for example [toLowerCase($Object/A) = toLowerCase($Value)] )

answered