Adding constraint for complex and multiple contract

Hi

Can I add constraint for a variable that it's complex and multiple?

I define family as a complex and multiple contract and adding constraints similar simple contract, but it doesn't work!

It's my code in constraints:

for(row in family){
    if(row.A.length() != 10)
        return false
}
return true;

If length of A doesn't equal to 10, it shows my error message but after correcting it doesn't work and still show error message!

I'm using Bonita Studio 7.8 community version.

Logs:

2021-07-07 13:20:00.796 +0430 WARNING: org.bonitasoft.engine.bpm.contract.validation.ContractConstraintsValidator THREAD_ID=53 | HOSTNAME=Pournajar | TENANT_ID=1 | Constraint [constraintFamily] on input(s) [family] is not valid
2021-07-07 13:20:00.796 +0430 INFO: org.restlet.Component.BonitaRestletApplication Error while validating constraints

Thanks

 

Hi,
Yes, you should be able to do that.

Can you try this expression (assuming A is a String):

return family*.A*.size().every { it == 10 }

Is there a more detail stack trace in the engine logs ?

HTH
Romain

Thanks it work.

If I have complicated constraints, Can I write a function there?

Thanks it work.

If I have complicated constraints, Can I write a function there?

Yes you can.

By example:

def boolean isGreaterThan(String value, int size){
return value.size() > size
}

return employeesInput*.name.every { isGreaterThan(it, 0) };

Thanks!

Hi Romain

In this way, for all row return one message. Is there a way that specify wrong row exactly?

Note that contract constraint is not meant for user validation, but contract data integrity.
If you need a proper validation feedback for the user it should be done javascript side (https://documentation.bonitasoft.com/bonita/2021.1/manage-control-in-forms).

Constraint error message is a technical error message that the end user should not see.

HTH
Romain

Ok, thanks.

For this goal, I added angular js module in my custom widget and if value was wrong, my class has been added like : ng-invalid-myCod

In this way, How do I show proper message after my custom widget?

Actually I'd like to add my message in ng-message of angular js!