How to return multiple references of composition BDM

 

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.

 

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

task input

 

{
  "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. 

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

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