Alfresco APS - Getting process instance name in a script

152 Views Asked by At

I need to develop a script that change dynamically the Process Instance name (in Alfresco APS 1.9). The change is conditional, like "If the name is 'ABC' then new name = 'ABC 2', else name = 'ABC 3' ".

I've found that to rename the Process Instance I can use the Groovy script below and it works fine:

execution.getEngineServices().getRuntimeService().setProcessInstanceName(execution.getProcessInstanceId(), "ABC 2");

But I need to get the current Process Instance name to check which would be the new name (How to get 'ABC' in my example above).

How can I get the Process Instance name using Groovy?

2

There are 2 best solutions below

0
On

Please try the below code snippet to get the Process Instance name.

HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance1.getProcessInstanceId()).singleResult();

 log.info(historicProcessInstance.getName());
1
On

Try:

execution.getProcessInstance().getName()

Or:

execution.getProcessInstance().getProcessDefinitionName()