Acces DAO from Grovvy Script


My main issue is to acces the DAO from a groovy script with the "BusinessObjectDAOFactory"

I'm working on project where I want to create a groovy script class to extenalize the "update my object", to not have to modify everywhere everytime something changes.
I have created a groovy scripts from "Development > Manage groovy scripts"

I tried to use the BusinessObjectDAOFactory, but it does really not works.

The code I try to use :


BusinessObjectDAOFactory BusinessObjectDAOFactory = new BusinessObjectDAOFactory();

BesoinDAO besoinDAO = BusinessObjectDAOFactory.loadClass(;



Where "Besoin" is a class from my database.

I have read some of questions on the formum but it does not fully answer my need.

3 answers



I have found a way to bypass my issue, but it's a bit dirty.
Anyone to help me ? :)

I think it's only a little ligne of code I don't have.


Thanks for your answer.

Actually it's not "outside" of Bonita, it's in the "groovy scripts" from Development > Manage Groovy Script, where you can define some basics functions to reuse during your process.

I have multiple forms where the user can update a buisness variable and I don't want to copy / past on every operation for every task

I want to create a function where I give the Map from the contract, then the function returns the object.

Then I think there is a simple way with the BusinessObjectDAOFactory Class.

But instread of using the createDAO, I should be able to use the loadClass.

I don't want to use the session / Tenant part:



I'm not sure what you mean by "externalize the 'update my object'", but this is how I'm accessing my BDM objects outside of Bonita through the API:

ProcessAPI processAPI = TenantAPIAccessor.getProcessAPI(session);

Map context = processAPI.getProcessInstanceExecutionContext(processInstanceId);

SimpleBusinessDataReferenceImpl objectRef = (SimpleBusinessDataReferenceImpl) context.get("object_ref");

BusinessObjectDAOFactory daoFactory = new BusinessObjectDAOFactory();

ObjectDAO objectDao = daoFactory.createDAO(session, ObjectDAO.class);

Object object = objectDao.findByPersistenceId(objectRef.getStorageId());

This requires a "session" object, so you need to log in with a user to create one.


If you define a Groovy Script Connector in Bonita studio (on a specific task), the editor has direct access to any of your BDM object DAO's, and you can interact with your objects without having to deal with sessions.

I know you said you want to avoid "modify everywhere every time something changes", but I have found Operations to be useful for updating my BDM objects after tasks are completed.