0
votes

I need to check if a process variable is empty so that I can keep a running total of tasks in my process.

I have a local process variable named totaltasks of type integer.

In my script I simply check if this variable is empty or null and then base the rest of the script off this:

//If process variable has never been initialised
if( execution.getVariable("totaltasks") === null && execution.getVariable("totaltasks") === 'undefined' ) {
    //set default value to 1 and initialise it
    int totalTasks = 1;
    execution.setVariable("totaltasks", totalTasks);
}
else {
    //otherwise, just increment the current value
    int totalTasks = (int)execution.getVariable("totaltasks");
    totalTasks += 1;
    execution.setVariable("totaltasks", totalTasks);
}

The code looks solid but I get the following error in my console:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.activiti.engine.ActivitiException: problem evaluating script: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: General error during class generation: null. Script6.groovy

What am I doing wrong here?

1
This is can't evaluate to true execution.getVariable("totaltasks") === null && execution.getVariable("totaltasks") === 'undefined' . You should use || instead - mrgrechkinn
Can you switch to JavaScript instead of groovy? Also use if( execution.getVariable("totaltasks")) it should return true as long as the variable has a value different than false. Be careful though as it would return true for an empty string as well! - Younes Regaieg

1 Answers

0
votes

You could simplify your code as below to avoid the MultipleCompilationErrorsException.

int totalTasksCount = execution.getVariable("totaltasks") as Integer
if(  totalTasksCount && totalTasksCount == 'undefined' ) {
    //set default value to 1 and initialise it
    int totalTasks = 1;
    execution.setVariable("totaltasks", totalTasks);
}
else {
    //otherwise, just increment the current value
    int totalTasks = totalTasksCount
    totalTasks += 1;
    execution.setVariable("totaltasks", totalTasks);
}