How to change assignee field for HistoricActivityInstance

Hi, I have a listener listening to FlowableEngineEventType.TASK_ASSIGNED event.
Below is a rough example of the custom listener:

TestListener.java

 public class TestListener implements FlowableEventListener
 {
     @Override
     public void onEvent( FlowableEvent event )
     {
         FlowableEngineEventType lEventType = (FlowableEngineEventType) event.getType();
 
         switch( lEventType )
         {
             case TASK_ASSIGNED:
                 if( event instanceof FlowableEntityEventImpl
                     && ( (FlowableEntityEventImpl) event ).getEntity() instanceof TaskEntityImpl )
                 {
                     TaskEntityImpl lTaskImpl = (TaskEntityImpl) ( (FlowableEntityEventImpl) event ).getEntity();
                     if( lTaskImpl.getAssignee() != null && lTaskImpl.getAssignee().equalsIgnoreCase( "TEST" ) )
                         lTaskImpl.setAssignee( "ADMIN" );
                     }
                     
                 }
                 break;
             default:
                 break;
         }
 
     }
     //other inherited method implementations
 }

With this lTaskImpl.setAssignee( "ADMIN" ); I’m able to change the assignee for the given user task from “TEST” user to “ADMIN”. But I get the old Assignee value i.e. “TEST” for the custom history APIs, which try to retrieve data from table act_hi_actinst

List<HistoricActivityInstance> historyList = mHistoryService.createHistoricActivityInstanceQuery()
                                                                    .processInstanceId( processInstanceId )
                                                                    .orderByHistoricActivityInstanceEndTime()
                                                                    .desc()
                                                                    .list()

Is there a way I can change the data of the history table as well while changing the assignee in TASK_ASSIGNED event?.

Hi akki,

have a look on TaskServiceImpl

    @Override
    public void setAssignee(String taskId, String userId) {
        commandExecutor.execute(new AddIdentityLinkCmd(taskId, userId, AddIdentityLinkCmd.IDENTITY_USER, IdentityLinkType.ASSIGNEE));
    }

org.flowable.engine.impl.cmd.AddIdentityLinkCmd#execute uses TaskHelper.changeTaskAssignee(task, identityId); dig little bit deeper into the source code and do exactly the same as TaskServiceImp is doing.
The problem could be that assignee is overridden after your update, but I would not expect it if you listener partially works.

Regards
Martin

Thanks for the reply. I’ll look into this.