currentUser() returns null in Call Activity


#1

Dear Camunda community,

In version v7.9.0-alpha2 I have a main process with user task and a call activity with the a user task inside. During execution of the call activity ${currentUser()} returns null, while the same variable returns a correct user in the main process. I have Input Variables mapped to all. What would be a proper way to pass currentUser() into a call activity?

Best regards,
Ilya


#2

Hi Ilya,

Is there an asynchronous continuation or other wait state between the user task and the point where ${currentUser()} is accessed?

Cheers,
Thorben


#3

Hi Thorben,

The main process has “asynchronous after” on user task (which works well with currentUser() and the same setting on further user tasks in a process after Call Activity. The Call Activity itself does not have any non-standard configurations (neither activity nor sub-process steps).I have a parallel gateway in sub-process if it is relevant.

Thank you.

Best regards,
Ilya


#4

Hi Ilya,

The currentUser context is only available in the transaction that is triggered by the user. That means, any EL expression that is executed by the job executor (i.e. after asynchronous continuation) and that uses currentUser fails. If you need to preserve that context, you could consider storing the current user in a process variable when the task is completed, for example by adding a task listener on the complete event.

Cheers,
Thorben


#5

Or model an outputparameter with name “userId” and value ${currentUser()}

Cheers, Ingo


#6

Hi Thorben,

Appreciate your response. I was trying to understand your explanation, but still struggling as probably do not have a good picture of the internal architecture. When you say

“to preserve that context, you could consider storing the current user in a process variable when the task is completed”

by task you refer to Call Activity as a whole or individual UserTasks?

Seems like in Call Activity I cannot capture currentUser() at any stage until Call Activity is finished.

Does it mean that in my case having two different UserTasks assigned to two different users inside Call Activity will block me from capturing both users?

Thank you.
Ilya


#7

Hi Ingo,

Thank you for your email. I believe this option would not work for my case as I am trying to capture users executing UserTasks within Call Activity…

Best regards,
Ilya


#8

If you set the variable in a subprocess, you have to add it to the variables out mapping of the call activity to access it in the main process.

Hope this helps, Ingo


#9

Hi @Ingo_Richtsmeier ,

Thank you for your suggestion. My set-up is slightly different:

Main User Task -> Call Activity User Task 1-> Call Activity User Task 2

I was trying to preserve user between User Task 1 and User Task 2 in Call Activity. I was experimenting yesterday and have found some sort of a solution for this using Task Listener in User Activity 1 attached to assignment event:

try {
    var current_user = task.execution.getProcessEngineServices().getIdentityService().getCurrentAuthentication().getUserId();
} 
catch (error) {current_user = ""} 
finally { 
      task.execution.setVariableLocal("current_user", current_user);
};

Thank you for your kind help.

Best regards,
Ilya