如何在activiti中获取运行流程实例的先前任务局部变量
How to get previous task local variables of a running process instance in activiti
我正在开发一个 spring 启动应用程序,使用 activiti 作为工作流引擎。 activiti-spring-boot-starter依赖版本为7.1.0.M6,spring-boot-starter-parent版本为2.6.7.
我已经使用 activiti-modelling-app 定义了一个 BPMN 2.0 图,现在我正在启动流程实例。完成一个任务后,我想在处理下一个任务时访问它的任务局部变量。我无法计算出它的 api。
我尝试使用 historyService
如下所示,但没有成功。我得到的结果列表每次都是空的 apis (finished()
, unfinished()
etc)
HistoricTaskInstance acceptMobile = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId)
.taskName("my-task1")
.singleResult();
有人可以指导我什么是正确的 api 来获取先前完成的任务的局部变量吗?
谢谢。
在任务之间传递变量的最佳方式是使用执行变量 DelegateExecution
执行变量是指向进程活动位置的特定指针,有关详细信息,请参阅 apiVariables
假设您有 Task-A
和 Task-B
以及不同的听众
这里是如何使用从 Task-A
到 Task-B
的执行变量:
@Component("TaskListenerA")
public class TaskListenerA implements TaskListener {
@Override
public void notify(DelegateTask task) {
DelegateExecution execution = task.getExecution();
if("complete".equals(task.getEventName()) {
String myTaskVar = (String) task.getVariable("taskAvariable")
execution.setVariable("exeVariable", myTaskVar);
}
}
}
@Component("TaskListenerB")
public class TaskListenerB implements TaskListener {
@Override
public void notify(DelegateTask task) {
DelegateExecution execution = task.getExecution();
String myVariable = execution.get("exeVariable");
}
}
我正在开发一个 spring 启动应用程序,使用 activiti 作为工作流引擎。 activiti-spring-boot-starter依赖版本为7.1.0.M6,spring-boot-starter-parent版本为2.6.7.
我已经使用 activiti-modelling-app 定义了一个 BPMN 2.0 图,现在我正在启动流程实例。完成一个任务后,我想在处理下一个任务时访问它的任务局部变量。我无法计算出它的 api。
我尝试使用 historyService
如下所示,但没有成功。我得到的结果列表每次都是空的 apis (finished()
, unfinished()
etc)
HistoricTaskInstance acceptMobile = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId)
.taskName("my-task1")
.singleResult();
有人可以指导我什么是正确的 api 来获取先前完成的任务的局部变量吗?
谢谢。
在任务之间传递变量的最佳方式是使用执行变量 DelegateExecution
执行变量是指向进程活动位置的特定指针,有关详细信息,请参阅 apiVariables
假设您有 Task-A
和 Task-B
以及不同的听众
这里是如何使用从 Task-A
到 Task-B
的执行变量:
@Component("TaskListenerA")
public class TaskListenerA implements TaskListener {
@Override
public void notify(DelegateTask task) {
DelegateExecution execution = task.getExecution();
if("complete".equals(task.getEventName()) {
String myTaskVar = (String) task.getVariable("taskAvariable")
execution.setVariable("exeVariable", myTaskVar);
}
}
}
@Component("TaskListenerB")
public class TaskListenerB implements TaskListener {
@Override
public void notify(DelegateTask task) {
DelegateExecution execution = task.getExecution();
String myVariable = execution.get("exeVariable");
}
}