activiti - 检查进程变量是否为空



我需要检查流程变量是否为空,以便我可以在我的进程中保持运行的任务总数。

我有一个名为 totaltasksinteger 类型的局部过程变量。

在我的脚本中,我只是检查这个变量是空的还是null的,然后脚本的其余部分基于这个:

//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);
}

代码看起来很可靠,但我在控制台中收到以下错误:

org.springframework.web.util.NestedServletException: Request 处理失败;嵌套异常是 org.activiti.engine.ActivitiException: 问题评估脚本: org.codehaus.groovy.control.MultipleCompilationErrorsException: 启动失败:类生成期间的常规错误:空。 脚本6.时髦

我在这里做错了什么?

您可以按如下方式简化代码以避免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);
}

最新更新