在进行项目开发时,读取流程中的变量时遇到了这样的问题:

org.jbpm.api.JbpmException: execution projectApplication.4028b204373f26c101373f318880000b doesn't exist

at org.jbpm.pvm.internal.cmd.GetExecutionVariablesCmd.execute(GetExecutionVariablesCmd.java:60)

at org.jbpm.pvm.internal.cmd.GetExecutionVariablesCmd.execute(GetExecutionVariablesCmd.java:36)

at org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)

at org.jbpm.pvm.internal.tx.SpringCommandCallback.doInTransaction(SpringCommandCallback.java:45

)

经过请教才知道是工作流的变量历史功能没有启用.

在工作流文件*.jpdl.xml中配置一下就可以.

<process description="项目立项申报流程" key="projectApplication" name="projectApplication" xmlns="http://jbpm.org/4.4/jpdl">

   <variable history="true" init-expr="${processType}" name="processType"  type="string"/>

   <variable history="true" init-expr="${projectId}" name="projectId"  type="string"/>

   <variable history="true" init-expr="${projectName}" name="projectName"  type="string"/>

其中variable就是配置项目.history设置为true,代表变量历史功能生效.init-expr和name就是要实现变量历史功能的变量了.

 

在程序中,通过以下代码获取历史流程变量:

historyService.getVariable(task.getExecutionId(), "projectId"));