How to update composition BDM with Groovy Script?

Hello,

I created composition BDM and add all contracts using by the groovy script 

Once I return the BDM I need to update all contract, so, I added update groovy script, however, I got the error,

Please help me what is the error to indicate.

Thanks in advance

This is the addall operation groovy script

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

 

And the this is update script .

 


recommandObjInput.each{
      testTimerList.add({ currenttestTimerInput ->
        //def testTimerVar = new TestTimer()
        def TestTimer testTimerVar = testTimerList.find{
            it.persistenceId == currenttestTimerInput.persistenceId.toLong()
        }
        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

 

And the error is 

returnType=java.util.Collection, dependencies=[SExpressionImpl [name=recommandObjInput, content=recommandObjInput, returnType=java.util.List, dependencies=[], expressionKind=ExpressionKind [interpreter=NONE, type=TYPE_CONTRACT_INPUT]]], expressionKind=ExpressionKind [interpreter=GROOVY, type=TYPE_READ_ONLY_SCRIPT]]
    at org.bonitasoft.engine.expression.impl.GroovyScriptExpressionExecutorCacheStrategy.evaluate(GroovyScriptExpressionExecutorCacheStrategy.java:160)
    at org.bonitasoft.engine.expression.impl.ExpressionServiceImpl.evaluate(ExpressionServiceImpl.java:86)
    at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionWithResolvedDependencies(ExpressionResolverServiceImpl.java:213)
    at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionsFlatten(ExpressionResolverServiceImpl.java:120)
    at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluate(ExpressionResolverServiceImpl.java:83)
    at org.bonitasoft.engine.core.operation.impl.OperationServiceImpl.evaluateRightOperandExpression(OperationServiceImpl.java:198)
    ... 26 more
Caused by: java.lang.NullPointerException: Cannot set property 'recommandation' on null object

 

 

 

Hello donghee.baik,

The update script is failing because the find() below is not returning any element:

def TestTimer testTimerVar = testTimerList.find {
    it.persistenceId == currenttestTimerInput.persistenceId.toLong()
} 

Have you tried executing the following instead?:

def TestTimer testTimerVar = testTimerList.find {
    it.persistenceId.toLong() == currenttestTimerInput.persistenceId.toLong()
}

 

Else, could you share the .bos of your process (or a sample one exposing the problem)?

Regards,

     Unai