Adding constraint for complex and multiple contract

1
0
-1

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

Comments

Submitted by nasrin788_1384620 on Wed, 07/07/2021 - 12:36

Thanks it work.

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

1 answer

1
+1
-1
This one is the BEST answer!

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

Comments

Submitted by nasrin788_1384620 on Wed, 07/07/2021 - 12:42

Thanks it work.

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

Submitted by romain.bioteau on Wed, 07/07/2021 - 12:53

Yes you can.

By example:

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

return employeesInput*.name.every { isGreaterThan(it, 0) };
Submitted by nasrin788_1384620 on Wed, 07/07/2021 - 13:18

Thanks!

Submitted by nasrin788_1384620 on Sun, 07/11/2021 - 08:56

Hi Romain

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

Submitted by romain.bioteau on Sun, 07/11/2021 - 10:24

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

Submitted by nasrin788_1384620 on Sun, 07/11/2021 - 11:25

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?

Submitted by nasrin788_1384620 on Mon, 07/12/2021 - 06:56

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

Notifications