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!
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%);
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
}
})
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
Have you found an answer? I have the same issue.
thanks
This worked correctly to me, I made an execution listener on the "start" of the Start Task and here is the code
public class SetAuthorAsWFInitiator implements ExecutionListener { private static final long serialVersionUID = 1095132995665073418L; @Override public void notify(DelegateExecution execution) throws Exception { AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Object>() { @Override public Object doWork() throws Exception { ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration(); Map<Object, Object> registeredBeans = processEngineConfiguration.getBeans(); ServiceRegistry serviceRegistry = (ServiceRegistry) registeredBeans.get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY); NodeService nodeService = serviceRegistry.getNodeService(); ActivitiScriptNode bpm_package = (ActivitiScriptNode) execution.getVariable("bpm_package"); List<ChildAssociationRef> childAssocs = nodeService.getChildAssocs(bpm_package.getNodeRef()); NodeRef documentNode = childAssocs.get(0).getChildRef(); List<AssociationRef> targetAssocs = nodeService.getTargetAssocs(documentNode, Constants.AUTHOR_ASSOC); NodeRef creatorNodeRef = targetAssocs.get(0).getTargetRef(); NodeRef creatorHomeFolderNodeRef = (NodeRef) nodeService.getProperty(creatorNodeRef, ContentModel.PROP_HOMEFOLDER); execution.setVariable("initiator", new ActivitiScriptNode(creatorNodeRef, serviceRegistry)); execution.setVariable("initiatorhome", new ActivitiScriptNode(creatorHomeFolderNodeRef, serviceRegistry)); processEngineConfiguration.getCommandExecutor().execute(new Command<Object>() { public Object execute(CommandContext commandContext) { commandContext .getHistoricProcessInstanceEntityManager() .findHistoricProcessInstance(execution.getProcessInstanceId()) .setStartUserId((String) nodeService.getProperty(creatorNodeRef, ContentModel.PROP_USERNAME)); return commandContext; } }); return null; } }, AuthenticationUtil.getAdminUserName()); } }
Ask for and offer help to other Alfresco Process Services and Activiti Users and members of the Alfresco team.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.