Just use a 'Rule' which checks the uniqueness from a BCo microflow
Retrieve action on Orderline within this rule has an XPath that looks something like below.
[Module.OrderlineOrder = $Orderline/Module.OrderlineOrder] [Seq = $Orderline/Seq] [id != $Orderline]
If an object is found the orderline sequence is not unique within the order
The same goes for a unique combi of attributes:
[id != $Orderline] [Attr1 = $Orderline/Attr1] [Attr2 = $Orderline/Attr2]
A simular question: same data model ORDER and ORDERLINE with a one to many relationship.
In ORDERLINE I would like an attribute LINENUMBER to increase by one automatically every time I add an ORDERLINE.
I tried to add this into the Domain model as a microflow for this attribute. I retrieve the Order, get a list of ORDERLINES (or empty). So far so good. But If i want to sort the list I get an error: "Calculated value cannot be used in its own calculation."
The solution of checking the uniqueness of combined attributes within a Before Commit microflow is not atomic and not thread safe. It will not guarantee uniqueness in a multi-user environment. However it could be very rare that duplication will arise. You could disallow the concurrent execution of the BC MF. But that is very restrictive and has side effects of error messages with rollback or running an alternative MF.
Concatenating the attributes in a new attribute in the entity with a uniqueness validation is guaranteed unique.
Otherwise you need a semaphore before the uniqueness check in the MF that allows only one thread at a time to pass and let others wait (like synchronized code in Java). One a single server deployment you could implement it in Java (global system storage) or in combination with the database. But on a multi-server environment (load-balanced) I do not think there is anything that could synchronize between threads on different servers. I even think that disallowing concurrent MF on different servers does not synchronize.