Execution Query doesn't return assignee info for claimed task

Hi, I have a requirement where I have to listen to an event like TASK_ASSIGNMENT, get assignee information, and update it in the entity. I’ve been able to accomplish it for a single user, but I’m facing an issue in the case of candidate groups.

To accomplish this, I have implemented FlowableEventListener and I’m listening to TASK_ASSIGNMENT of FlowableEngineEventType. Along with this, I’m using RuntimeService to create ExecutionQuery and get the information related to the currently active task. Below is the code:

WorkflowEventListener.java:

public class WorkflowEventListener implements FlowableEventListener
{

    @Autowired
    private RuntimeService mRuntimeService;

    @Override
    public void onEvent( FlowableEvent event )
    {
        FlowableEngineEventType lEventType = (FlowableEngineEventType) event.getType();

        switch( lEventType )
        {
            case TASK_ASSIGNED:
                if( event instanceof FlowableEntityEventImpl )
                {
                    FlowableEntityEventImpl lFlowableEntityEventImpl = (FlowableEntityEventImpl) event;
                    String lProcessInstanceId = lFlowableEntityEventImpl.getProcessInstanceId();
                    List<Execution> lExecutions = mRuntimeService.createExecutionQuery()
                                                                 .processInstanceId( lProcessInstanceId )
                                                                 .list();
                    UserTask lUserTask = new UserTask();

                    if( lExecutions.size() > 0 )
                    {

                        for( Execution lExecution : lExecutions )
                        {
                            if( ( (ExecutionEntityImpl) lExecution ).getCurrentFlowElement() instanceof UserTask )
                            {
                                lUserTask = (UserTask) ( (ExecutionEntityImpl) lExecution ).getCurrentFlowElement();
                            }
                        }

                        System.out.println( "Assignee info: " + lUserTask.getAssignee() );
                    }
                }

                break;
            default:
                break;
        }
    }

    @Override
    public boolean isFailOnException()
    {
        return false;
    }

    @Override
    public boolean isFireOnTransactionLifecycleEvent()
    {
        return false;
    }

    @Override
    public String getOnTransaction()
    {
        return null;
    }

}

Normally, if I inspect elements in lExecutions , I get information about the assignee of the currently active task. For a basic flow, lExecutions will contain 2 elements, one will be ProcessInstance and other will be ExecutionEntityImpl.
Issue comes when a task is assigned to a group and a user claims the task.
Claiming the task is done via single API call, taskService.claim(). Once I get into the listener and after the claim has happened, I was expecting the assignee info to be populated in currentFlowElement, but assignee remains still null.

I’m not sure why lExecutions is not having assignee information once the task is claimed.
Please let me know if I’m missing any information from my end.

I was looking more into the issue and I found that TASK_ASSIGNMENT event is thrown when taskService.claim() call is made. I am able to get the details of active task once claimTask call is finished. I believe the reason assignee info is not updated in Execution, is because claimTask call is still in progress and not finished yet.

That’s correct indeed.
If really needed, you can use the ExecutionEntityManager (retrievable through CommandContextUtil) to get the current not-yet flushed version of the execution.

1 Like

Thanks, Joram this will be useful. However, for now, I just performed my task once the claiming was done. But