Process initiator name using expression

Hi, I have a requirement to find the process initiator name using expression so that I can set it to a process variable or using java Api as well.

please help me on this.

Hi @abhi1o3,

Camunda supports an attribute on the start event to store the user id into a process variable: https://docs.camunda.org/manual/7.12/reference/bpmn20/custom-extensions/extension-attributes/#initiator

There is a field in the modeler property panel on the start event to enter the variable name.

It is used in the Java API, if you call identityService.setAuthenticatedUserId() before runtimeService.startProcessInstanceByKey().

Otherwise the value will be null.

Hope this helps, Ingo

thankyou for your early response. right now I am already setting initiator name on start event. but my requirement is to how we can get the initiator name using expression or java code so that I can show this on mail body.

Incase of rest api, do we need to fire two api calls for setting initiator & starting process instance?

Hi @abhi1o3,

as it is saved as a common process variable, you can access the value as any other variable.

In a JavaDelegate or ExecutionListener use execution.get("varName");

On a sequence flow condition or in a user assignee use ${varName}.

Hope this helps, Ingo

can you tell me after this how I can get the first name and last name of that initiator
as I have a requirement of getting the firstname and last name of the initiator
is there any kind of expression to get it.

Hi @aravindhrs,

to use this feature with the REST API, add the authentication Filter in the REST Api web application. For basic enablement in spring boot, have a look at this example: https://github.com/camunda/camunda-bpm-examples/tree/master/authentication/basic.

If you use the camunda-bpm-spring-boot-starter-rest, you can use more of the spring magic like here: https://github.com/camunda-consulting/code/tree/master/snippets/springboot-rest-api-basic-auth

When you start a process, the authenticated user is saved as initiator.

Hope this helps, Ingo

Hi @abhi1o3,

you have to execute a user query to get his details. Have a look into the example here: https://docs.camunda.org/manual/7.12/user-guide/process-engine/identity-service/

Hope this helps, Ingo

I wrote the code same way as there in example:
https://docs.camunda.org/manual/7.12/user-guide/process-engine/identity-service/

but to have conditon . can you tell me how to get the service task name in delegate class?

@abhi1o3 execution.getCurrentActivityName() can give you the name of service task.

@Slf4j
 public class LoggerDelegate implements JavaDelegate {

   @Override
    public void execute(DelegateExecution execution) throws Exception {
       log.info("TaskName:{}", execution.getCurrentActivityName());
    }
 }