how to load data from the database as local variables?
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()
BusinessObjectDAOFactory daoFactory = new BusinessObjectDAOFactory();
ContractDAO contractDAO = daoFactory.createDAO(SESSION_IS_REQUIRECT, ContractDAO.class);
Contract contract = contractDAO.findByPersistenceId(bill.contractId);
As per version 7.4 I would use the following
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.
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
In this case will the variable contractDAO exist or not since the class com.company.model.contractDAO has the same name?
Thanks a lot