Hi, I have a workflow something like this:
In code, I have an Event Listener which implements FlowableEventListener
that listens to the event TASK_CREATED
.
In the above workflow, after the completion of User Task 1
, TASK_CREATED
event is thrown once the execution comes there.
Using below code, I’m able to get the details of User Task 2
in lUserTask
,
@Override
public void onEvent( FlowableEvent event )
{
FlowableEngineEventType lEventType = (FlowableEngineEventType) event.getType();
switch( lEventType )
{
case TASK_CREATED:
if( event instanceof org.flowable.common.engine.impl.event.FlowableEntityEventImpl )
{
org.flowable.common.engine.impl.event.FlowableEntityEventImpl lFlowableEntityEventImpl = (org.flowable.common.engine.impl.event.FlowableEntityEventImpl) event;
String lProcessInstanceId = lFlowableEntityEventImpl.getProcessInstanceId();
List<Execution> lExecutions = mRuntimeService.createExecutionQuery()
.processInstanceId( lProcessInstanceId )
.list();
UserTask lUserTask = new UserTask();
for( Execution lExecution : lExecutions )
{
if( ( (ExecutionEntityImpl) lExecution ).getCurrentFlowElement() instanceof UserTask )
{
lUserTask = (UserTask) ( (ExecutionEntityImpl) lExecution ).getCurrentFlowElement();
}
}
But if I try to use task service to set assignee for this user task, like this
taskService.setAssignee( lUserTask.getId(), "admin" )
I get an error saying Cannot find task with id user-task-2
.
I tried to get all the tasks for given process instance ID using,
List<Task> lTasks = mTaskService.createTaskQuery().processInstanceId( lProcessInstanceId ).list();
This gave me only User Task 1
.
I’m assuming the task details are not yet flushed to table, which is used by taskService to get the details (let me know if I’m incorrect).
So, is there a way I can edit the assignee for the User Task 2
, for which the TASK_CREATED
was thrown?
Let me know if any information is needed from my side.
Thanks in advance.