Access DAO object in Constraint script

1
0
-1

Hello All,

It seems it's not possible to access DAO objects in a Constraint validation script. For instance, when I try to validate using objectDAO.findByCode(input.myCode, 0, 1), I get the following error:

objectDAO is neither defined in the script nor in dependencies.

Is it so or am I doing something wrong? And if so, what alternative is feasible to validate input data against BDM (database) values?

Thank you in advance.

2 answers

1
0
-1
This one is the BEST answer!

Actually for constraints definition you can only use contract inputs and you don't have access to external data such as business data.

What I can recommend is to do the validation as much as possible in the forms where you can actually call the API to get business data values.

Also if needed you might want to store receive data in process variable and then do some verification in a dedicated step in the process. You can then store the result of the validation as well in a process variable and use it in gateway to route the process execution.

Comments

Submitted by edo_2 on Tue, 07/11/2017 - 19:01

Antoine,

Thank you for your promptly answer.

The problem in this case is we are trying to validate an item which is part of a complex object. We created a custom widget that would only accept correct values, but couldn't find a way to assign it to the specific value. For some reason, the designated variable arrived at the backend empty, although we were using the exact variable name that the form was generated with.

Then, we tried this back-end validation.

I'll explain a little more our scenario: We are entering an invoice with a header and detail lines. We want to make sure the detail lines refer to actual product codes (codes which are different from the product persistenceId).

In this scenario, how can we validate a detail line item against a BDM object?

Regards,

Edo.

Submitted by chris.lowth on Wed, 07/12/2017 - 00:02

I had to do this in my application, and had to cheat to get it to work.

What I did in the end was to add a function to a custom groovy script which went direct to the database, bye-passing bonita's persistence layer. I'm using MySQL, so I used the java.sql library to do it. It's safe to do for queries, but avoid doing any updates.

I hate having to do it that way, but until Bonita provide access to the API objects inside a constraint validator it's what you're stuck with.

It works - but it isn’t nice.

Chris

Submitted by antoine.mottier on Wed, 07/12/2017 - 09:23

About your issue with the variable arriving empty, maybe you can create another question and share your diagram + BDM as a .bos file so I can take a look?

Submitted by edo_2 on Wed, 07/12/2017 - 15:58

Antoine,

I'll do as you suggest.

Best regards.

Edo.

1
0
-1

Chris,

I'll look for better ways to solve this issue. I'll share with you whatever I find.

Best regards,

Edo.

Notifications