How to Modify the name of a process instance in runtime?

To modify the name of an instance of the process in runtime, I used the following code in a script task.
Is it the right way? Is there a better alternative?

var idProcessInstance = execution.getProcessInstanceId();
runtimeService.setProcessInstanceName(idProcessInstance, ‘Name…’);


That’s fine, going through the runtimeService in a script will reuse the the current command context and doesn’t start a new transaction.

Thanks Joram for the answer