how to load data from the database as local variables?

1
0
-1

Have a service task where I am trying to make financial calculations. The data comes from a bill and the bill contains a contract id (This is a persistence id). I was hoping to use that to load the contact and get its data.

I was planning to load the data inside a local variable by adding the code below to data >> local variable >> add >> Edit variable dialog >> edit expression dialog >> script
However, I have no clue how to get the session. The session is required to call BusinessObjectDAOFactory.createDAO()

import org.bonitasoft.engine.bdm.BusinessObjectDAOFactory
import org.bonitasoft.engine.session.APISession;

import com.company.model.Contract
import com.company.model.ContractDAO

BusinessObjectDAOFactory daoFactory = new BusinessObjectDAOFactory();

ContractDAO contractDAO = daoFactory.createDAO(SESSION_IS_REQUIRECT, ContractDAO.class);
Contract contract = contractDAO.findByPersistenceId(bill.contractId);

return contract;

1 answer

1
0
-1

As per version 7.4 I would use the following

import com.company.model.Contract
import com.company.model.ContractDAO

def cont = contractDAO.findByPersistenceId(bill.contractId)

That does the trick. However Bonita discourages using non-business variables to store business data and you may not need declaring local variable in Bonita at all. Just get your bill in calculation script using DAO.

Comments

Submitted by o.senouci on Wed, 07/05/2017 - 09:48

It works. So thanks a lot. However I still don't understand how contractDAO got initiated! It's a bit strange that by importing the namespace, suddenly contractDAO cames to existence.

What happens if the BDM was named com.company.model.contract? Notice that the model name starts with a lowercase and not an upper case.

This will result in the DAO being named com.company.model.contractDAO.

In this case will the variable contractDAO exist or not since the class com.company.model.contractDAO has the same name?

Thanks a lot

Notifications