How to assigne a task for a user

I created a process in camunda modeler .
I created a form in the start event with “long” type.
When the process is run, in the first, the process will ask the user to put a number in the form that I created in the start event.

I want to userTask that followed after the start event, will assign to that number which I created in the start event.

That number is users id.

yes, you can do it. The form variables values you entered can be used to mark assignee for the task. at runtime, you can refer that number to task.assignee will become assignee of that user task.

In bpmn model, for the user task activity, while modelling bpmn model you can find assignee field in properties panel. Using expressions or task listener you can set assignee for the task which was entered in the form. Note that variable should match the variable in the form. Refer the below model,

other way is, writing task listener and configure it in start event of the user task and set it via delegateTask.setAssignee("83282929");

Note: Assignee field is of type string, so don’t forget to typecast from long to string type using String.valueOf(longValue);

1 Like

Hi @aravindhrs
Thank you for your answer.
I edited my mode and that worked fine .

I have another question :

How can i write unit test for this model ?
Can I create a variable with “user_id” and set a value for that and in test section , when i test the userTask assertation , i check the assignee with :


can I ?

Another way of parsing long variable using javascript in listener:

 assertEquals("user", taskService.createTaskQuery().singleResult().getAssignee());

Hi @rezza72,

your test for the assigned user using BPM Assert syntax should just be perfectly fine, yes.

Where and how you set the variable for the test massively depends on what your model looks like. If I understand your model correctly you probably want to pass the variable on starting your test process instance like

ProcessInstance processInstance = runtimeService().startProcessInstanceByKey("process-definition-key", withVariables("user_id", "83282929"));