Gettting error: "Unable to evaluate expression without a definitionId" in a groovy script

When I put the following code inside a groovy script to provide the “Loop while” value in a standard loop:

import java.util.logging.Logger;
Logger logger = Logger.getLogger(“org.bonitasoft”);
logger.severe(“iterate”);
loopVar++;
if (loopVar > loopEnd) {
return true;
}
else {
return false;
}

I get an exception:

2015-06-05 18:20:25 org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork
SEVERE: THREAD_ID=109 | HOSTNAME=Phillips-MacBook-Air.local | TENANT_ID=1 | The work [ExecuteFlowNodeWork: processInstanceId:11, flowNodeInstanceId: 42] failed. The failure will be handled.
2015-06-05 18:20:25 org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork
SEVERE: THREAD_ID=109 | HOSTNAME=Phillips-MacBook-Air.local | TENANT_ID=1 | org.bonitasoft.engine.core.process.instance.api.exceptions.SActivityStateExecutionException : "PROCESS_DEFINITION_ID=7018794897348539495 | PROCESS_NAME=testloop | PROCESS_VERSION=1.0 | PROCESS_INSTANCE_ID=11 | ROOT_PROCESS_INSTANCE_ID=11 | FLOW_NODE_DEFINITION_ID=-7795268830872498336 | FLOW_NODE_INSTANCE_ID=42 | FLOW_NODE_NAME=Step1 | org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Groovy script throws an exception of type class org.bonitasoft.engine.commons.exceptions.SBonitaRuntimeException with message = Unable to evaluate expression without a definitionId
Expression : SExpressionImpl [name=incrementLoop, content=import org.bonitasoft.engine.connector.ConnectorException;
import org.bonitasoft.engine.bpm.process.ProcessDefinition;
import org.bonitasoft.engine.api.ProcessAPI;

import java.util.logging.Logger;
Logger logger = Logger.getLogger(“org.bonitasoft”);
logger.severe(“iterate”);
loopVar++;
if (loopVar > loopEnd) {
return true;
}
else {
return false;
}, returnType=java.lang.Boolean, dependencies=[SExpressionImpl [name=loopVar, content=loopVar, returnType=java.lang.Integer, dependencies=, expressionKind=ExpressionKind [interpreter=NONE, type=TYPE_VARIABLE]], SExpressionImpl [name=loopEnd, content=loopEnd, returnType=java.lang.Integer, dependencies=, expressionKind=ExpressionKind [interpreter=NONE, type=TYPE_VARIABLE]]], expressionKind=ExpressionKind [interpreter=GROOVY, type=TYPE_READ_ONLY_SCRIPT]]"
org.bonitasoft.engine.core.process.instance.api.exceptions.SActivityStateExecutionException: PROCESS_DEFINITION_ID=7018794897348539495 | PROCESS_NAME=testloop | PROCESS_VERSION=1.0 | PROCESS_INSTANCE_ID=11 | ROOT_PROCESS_INSTANCE_ID=11 | FLOW_NODE_DEFINITION_ID=-7795268830872498336 | FLOW_NODE_INSTANCE_ID=42 | FLOW_NODE_NAME=Step1 | org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Groovy script throws an exception of type class org.bonitasoft.engine.commons.exceptions.SBonitaRuntimeException with message = Unable to evaluate expression without a definitionId
Expression : SExpressionImpl [name=incrementLoop, content=import org.bonitasoft.engine.connector.ConnectorException;
import org.bonitasoft.engine.bpm.process.ProcessDefinition;
import org.bonitasoft.engine.api.ProcessAPI;

import java.util.logging.Logger;

This is version 6.5.1 community, java version “1.8.0_45”, tomcat server that is packaged with 6.5.1 community edition.

Anyone know how to fix this? Thanks in advance,
Phil

1 Like

You are assuming that loopVar is writeable, this is not the case.

The following should work

def tempLoopVar = loopVar+1; if (tempLoopVar > loopEnd) { regards

Thanks for the quick response, Sean. However, I still get the same definitionID exception, even when the groovy script looks like this:

import java.util.logging.Logger;
Logger logger = Logger.getLogger(“org.bonitasoft”);
logger.severe(“iterate”);
//loopVar++;
//if (loopVar > loopEnd) {
// return true;
//}
//else {
// return false;
//}

This is what I always use. But yours is (basically) the same.

Try creating a brand new process, and only write to log…no variables or anything…see if that works.

You could remove the whole connector first as well to clean it up, save and exit Studio, and then add it back…see what happens

regards

import java.util.logging.Logger;

int dI = 0;
boolean debug = true;
String nameOfConnector = “myConnectorName”; //change for every connector

ProcessRuntimeAPI processRuntimeAPI = apiAccessor.getProcessAPI();
String processName = processRuntimeAPI.getProcessInstance(processInstanceId).getName();

//set the name of the routine
String thisTrace = " “+processName+” “+nameOfConnector +”: ";

Logger logger= Logger.getLogger(“org.bonitasoft”);
if(debug){dI++; logger.severe(dI+thisTrace+“Trace Start”);}
if(debug){dI++; logger.severe(dI+thisTrace+“Trace End”);}