How to load a business data from a multi-instanciated subprocess into a multiple business data of the main process

1
0
-1

Hello,

I have a multi-instanciated subprocess that returns informations about one Car at a time,
and I want to collect them for all the cars, in the root process.

So, the subprocess contains a business variable subCarDataItem, which is defined after the Business object carObject(attributes : id, make, model).

The root process contains 2 business variables :
- mainCarDataItem, defined after carObject
- wholeCarData, defined as a list of carObject

As defined in the call activity that runs the subprocess, in the "data to receive" section, subCarDataItem of the subprocess is assigned mainCarDataItem of the root process.

That means that mainCarDataItem only contains the data of the last iteration of the subprocess.

I've tried to add an operation in the call activity, that adds the content of mainCarDataItem into the list wholeCarData, but it doesn't work ("class BScript391$_run_closure2 cannot be cast to class org.bonitasoft.engine.bdm.Entity").

The operation is defined like this :
"wholeCarData takes the value of script()" :
and the script is :
def trtList = []

if (!wholeCarData.empty ) {
wholeCarData.each{ trtList.add({ currentline ->
def trtVar = new com.company.model.carObject()
trtVar.id = currentline.id
trtVar.make = currentline.make
trtVar.model = currentline.model
return trtVar
}(it))
}}

trtList.add({def trtVar = new com.company.model.carObject()
trtVar.id = mainCarDataItem.id
trtVar.make = mainCarDataItem.make
trtVar.model = mainCarDataItem.model
return trtVar
})

return trtList

What is wrong with that ?

Thank you in advance for your answer(s)

Regards,
Thierry.

1 answer

1
0
-1

Hello,

The point is in the root process, the "mainCarDataItem " is not a LOCAL data, but a PROCESS data. All BDM processes are PROCESS DATA.

So, when in the "data to received" you believed that you receive locally and assign the mainCarDataItem, actually, you update a PROCESS data. So, you may face an issue when there is 2 thread running the call activity returns at the same time (normally, Bonita has a lock to manage only one execution on a case at one moment).

So, I would prefer if you return the PersistenceID from the subprocess, then in your script, do a find() on this persistenceId, then add it in your list.

Saying that what you did should work. The question is : in your script, where the "currentline" come from? Could you add some logs to determine where the error comes from? it may come from the result (add a log just before each "return"). I suspect too that the return information (a list of CarObject) is not what you expect (the expected result is not a list for example).

Best,

Notifications