How to change who started a process?

cancel
Showing results for 
Search instead for 
Did you mean: 
Active Member

How to change who started a process?

Currently when I'm starting a process, I set the authenticatedUserId through the identity service. I would like to change who started a project (transfer ownership functionality). I have changed the identity links, however when querying process instances with `.startedBy()`, it still shows the old user as having started the process. Any help would be greatly appreciated.

Example:

historyService
        .createHistoricProcessInstanceQuery()
        .startedBy("OLDUSER")
        .unfinished()
        .list()

Thanks!

3 Replies
Senior Member

Re: How to change who started a process?

Perhaps,there is no public API for your use case.

You need to use dao directly as follows.

Example:

Context.getCommandContext()
.getHistoricProcessInstanceEntityManager()
.findHistoricProcessInstance(%ProcessInstanceId%)
.setStartUserId(%UserId%);

Active Member

Re: How to change who started a process?

In my case Context.getCommandContext() is returning null. Any idea why?

I tried 

processEngineConfiguration.commandExecutor.execute(new Command<Object>() {
    Object execute(CommandContext commandContext) {
        commandContext
            .getHistoricProcessInstanceEntityManager()
            .findHistoricProcessInstance(id)
            .setStartUserId(username)
    }
})

and it doesn't fail, however the change doesn't take effect

I've also tried the following

processEngineConfiguration.commandExecutor.execute(new Command<HistoricProcessInstance>() {
    HistoricProcessInstance execute(CommandContext commandContext) {
        HistoricProcessInstanceEntityManager manager = commandContext.getHistoricProcessInstanceEntityManager()
        HistoricProcessInstance instance = manager.findHistoricProcessInstance(id)
        instance.setStartUserId(username)
        commandContext.dbSqlSession.update(instance)
        instance
    }
})
Active Member

Re: How to change who started a process?

Looks like what I'm trying to do is not possible:

Activiti/HistoricProcessInstance.xml at master · Activiti/Activiti · GitHub 

The update statement gets executed, but start_user_id is not part of the fields that get set