cancel
Showing results for 
Search instead for 
Did you mean: 

Modify process instance name

mrahn
Confirmed Champ
Confirmed Champ

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

1 ACCEPTED ANSWER

daisuke-yoshimo
Star Collaborator
Star Collaborator

> 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%)}

View answer in original post

12 REPLIES 12

daisuke-yoshimo
Star Collaborator
Star Collaborator

> 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%)}

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.

agnishu
Champ on-the-rise
Champ on-the-rise

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);

mrahn
Confirmed Champ
Confirmed Champ

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

When do you want to change process instance name?

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.

daisuke-yoshimo
Star Collaborator
Star Collaborator

> 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.

Thank you for your reply.
I made the sample for your use case.

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?

daisuke-yoshimo
Star Collaborator
Star Collaborator

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.