How to return multiple references of composition BDM

1
0
-1

Hello, I am sorry to ask without making sure about the question.

I am developing a small to do task process.

I created multiple business object models with composition bdm.

open?id=1CPSYLy8lSt0x-9qXKTHvGiAOKfIDeuPM

open?id=1ANjCrObKPqETnTYHSfF9fHBy-SHcXhEg

In my UI, I can send the data as follows.

view?usp=sharing

{
"timerObjInput": [
{
"recommandation": "Recommandation 1",
"timerTask": [
{
"title": "Task 1",
"startdate": "2019-02-07T00:00:00.000Z",
"enddate": "2019-02-07T00:00:00.000Z",
"statusTask": "None"
},
{
"title": "Task2",
"startdate": "2019-02-07T00:00:00.000Z",
"enddate": "2019-02-07T00:00:00.000Z",
"statusTask": "None"
}
],

"statusRec": "In process"
}
]
}

However, when I return the business variable the result is

recommandObj
[
{
"persistenceId": 165,
"persistenceId_string": "165",
"persistenceVersion": 0,
"persistenceVersion_string": "0",
"recommandation": "Recommandation 1",
"statusRec": "In process",
"links": [
{
"rel": "timerTask",
"href": "/API/bdm/businessData/com.company.model.TestTimer/165/timerTask"
}
]
}
]

I created a groovy script to add all data to BDM

def testTimerList = []
//For each item collected in multiple input
boolean status = false;

timerObjInput.each{
//Add a new composed testTimer instance
testTimerList.add({ currenttestTimerInput ->
def testTimerVar = new com.company.model.TestTimer()
testTimerVar.recommandation = currenttestTimerInput.recommandation
testTimerVar.statusRec = currenttestTimerInput.statusRec;
testTimerVar.timerTask = {
def timerTaskList = []
//For each item collected in multiple input
currenttestTimerInput.TimerTask.each{
//Add a new composed timerTask instance
timerTaskList.add({ currenttimerTaskInput ->
def timerTaskVar = new com.company.model.TimerTask()
timerTaskVar.title = currenttimerTaskInput.title
//timerTaskVar.setStartdate((new Date()).format('yyyy.MMMMM.dd hh:mm aaa'));
timerTaskVar.statusTask = currenttimerTaskInput.statusTask
timerTaskVar.startdate = currenttimerTaskInput.startdate
timerTaskVar.enddate = currenttimerTaskInput.enddate
return timerTaskVar
}(it))
}
return timerTaskList}()
return testTimerVar
}(it))
}
return testTimerList

How can I return the data what I send to the task?

Any help would be appriciated .

Thanks in advance.

1 answer

1
+1
-1
This one is the BEST answer!

Hello donghee.baik,

What you are seeing (i.e. a reference link being returned for your composed object, instead of the object itself), is what is expected when your object composition is defined as "Only load related objects when needed" (a.k.a. "lazy"), as the documentation of the BDM REST API explains.

If you want your object to be systematically returned in full, you should define your composition relationship as "Always load related objects" (a.k.a. "eager").

Otherwise, if you wish to keep your composed objects as "lazy", you will have to explicitely retrieve those objects using the appropriate "getter" methods of your object's DAO in your script. But in such case, beware, it will only work provided the script is executed inside a transaction: for instance, it will not work if your Groovy script is a connector, because connectors are executed outside a transaction; however, it will work if the script is part of the input parameters or the operations of a connector or task, which are executed in a transaction by the engine.

I hope this helps.

Unai

Comments

Submitted by donghee.baik on Tue, 02/12/2019 - 16:04

Thanks a lot, Unai.

I changed the option as "Always load related objects" and it works now. Thanks for your explanation as well.

It helps me a lot.

I appreciate your help.

Thanks.

Donghee

Notifications