Assign first task to start user

Hi all,

I want my first task to be assigned to the user starting the process ( ${initiator} ).
Is it possible without an additional task in between the start process and the first user task?

I tried several listeners so far, always with the same groovy script without success;

def initiator = execution.getProcessEngineServices().getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId()).singleResult().getStartUserId() execution.setVariable('initiator',initiator)

Start event ‘start’ execution listener → query returns null
User task ‘start’ execution listener → query returns null
User task ‘create’ task listener → task is initialized already and ${initiator} identifier cannot be resolved

Extra info; history service is configured as FULL

Hi,

Instead of using the startUserId of the HistoricProcessInstance (which is not persistent yet when you try to query for it), you could use the methods IdentityService#getCurrentAuthentication and Authentication#getUserId to determine the start user. That is exactly the way the startUserId is populated anway.

Cheers,
Thorben

On the start event you can fill in the property “Initiator” and by this provide the name of a variable in which the id of the user who started the process is stored. You would then reference that in the usertask.

Example

<startEvent camunda:initiator="varName" ...  />

<userTask camunda:assignee="${varName}" ... />
4 Likes

Thank you, @DanielMeyer!

I did not know the initiator value of a start event was actually the assigner of the value.

@DanielMeyer What does the Initiator extension do? Because we just keep using the self-defined variable name, why is the initiator extension used? (I mean what does providing the varName in the initiator extension do behind the scenes?)

1 Like

Hi Stephen,

camunda:initiator just defines a process variable with the name varName to keep the userID of the logged in user who started the process instance from the tasklist-start-process-page (or from an authenticated rest call). And the engine fills the value.

Cheers, Ingo

@Ingo_Richtsmeier the example i am looking at is something like if you start a process through the API. You can send a variable as part of the start process API call to represent your “initiator”. Defining the initiator as a start event extension is not necessarily needed. I guess I am asking what does defining which variable name is used to represent he initiator as part of a start event extension actually do? Is this for the purposes the Model API?

Hi Stephen,

are these the lines you are looking for?

If you start a process by java api, you need to call identityService.setAuthenticatedUserId() first to fill the value.

Maybe its a just a feature for convenience if you start your process directly from the camunda tasklist.

Cheers, Ingo

ya looks like a helper specifically for tasklist ?
Because if I read this correctly, if you were starting a process through the API and there is no auth user, then authenticatedUserId would be sort of irrelevant. ?

You can use it in broader way (not only tasklist), if you do an authenticated service call.

If you start the process instance without authentification, the variable will be empty.

Cheers, Ingo