05-10-2017 02:22 AM
Dear community.
Is there a way to modify the name of a process instance?
I'd prefer to use an execution (or task) listener for this purpose. Having ${processInfoBean.getProcessName(execution)} to get the process instance name I wonder whether there is a method to modify the process instance name.
Best regards
Marco
05-10-2017 02:47 AM
> Is there a way to modify the name of a process instance?
You can user public api 'RuntimeService.setProcessInstanceName(String processInstanceId, String name)'.
RuntimeService (Activiti - Engine 5.22.0 API)
* Java example
execution.getEngineServices().getRuntimeService().setProcessInstanceName(execution.getProcessInstanceId(), %NAME%);
* Expression example
${execution.getEngineServices().getRuntimeService().setProcessInstanceName(execution.getProcessInstanceId() , %NAME%)}
05-10-2017 02:47 AM
> Is there a way to modify the name of a process instance?
You can user public api 'RuntimeService.setProcessInstanceName(String processInstanceId, String name)'.
RuntimeService (Activiti - Engine 5.22.0 API)
* Java example
execution.getEngineServices().getRuntimeService().setProcessInstanceName(execution.getProcessInstanceId(), %NAME%);
* Expression example
${execution.getEngineServices().getRuntimeService().setProcessInstanceName(execution.getProcessInstanceId() , %NAME%)}
10-21-2019 10:29 AM
Your solution works very well. But I have a question, is it possible to use a process variable in the process name? I tried to use a variable eg ${ClaimNumber} but unfortunately it doesn't work for me.
11-25-2019 01:39 AM
this may not be possible because the name is set just after the process start and h epocess insance might not be aware of this variable.
however if you started your process through Java code, then you can sart a process and immediately set a name of your choice. it can be a dynamic value passed from outside.
suppose "title" is a variable, you can create REST end point and execute this. you can then see this started process in the UI.
ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey("someKey", variables);
processEngine.getRuntimeService().setProcessInstanceName(processInstance.getId(), title);
05-12-2017 09:07 AM
Thank you daisuke-yoshimoto!
Your reply was very helpful!
Since it didn't seem to work for me I imported your process and it didn't work either.
What I found so far is, that modifications of the process intance name doesn't work before end of the first user task. So for the first user task it does not work with the Start event of the Execution Listener or the Create event of the Task Listener. But it does work with the End event of the Execution Listener and the Complete event of the Task Listener. For the second user Task it does work with the Start event of the Execution Listener and the Create event of the Task Listener. Using a Service Task (or Script Task) between Start and the first user task doesn't help as well. The process name cannot be modified before the end of the first user task.
We run Alfresco Process Services 1.6.0.
Best regards
Marco
05-12-2017 09:27 AM
When do you want to change process instance name?
05-12-2017 09:58 AM
The best would be using an Execution listener of the Sequence flow just before the first user task. Doing so I'd be able to modify the process instance name before the first user gets involved.
05-12-2017 10:13 AM
05-12-2017 10:37 AM
Mmmhhh, as I wrote: this doesn't work. In my system modifications of the process name don't work before the end of the first user task.
Does it work for you?
05-12-2017 11:40 PM
I'm sorry, I didn't checked it in the same environment as you.
I checked it with Activiti engine 5.21.0.
Now, I checked it in the same environment as you(Alfresco Process Services 1.6.1) and got error as follows.
org.activiti.engine.ActivitiException: Unknown method used in expression: ${execution.getEngineServices().getRuntimeService().setProcessInstanceName(execution.getProcessInstanceId() , 'mod_name')}] with root cause
org.activiti.engine.impl.javax.el.MethodNotFoundException: Cannot find method 'getEngineServices' in 'class
Probably, it seems that Alfresco Process Services limit EL expression, unlike Activiti Engine.
You can use modify process instance name by using an Execution listener(directly java program).
I made sample code and uploaded.
Explore our Alfresco products with the links below. Use labels to filter content by product module.