How to change task name in tasklist

Hello,

I want to know how to change user task name in tasklist.
This is my flow:
step1: Get message from Message queue(rabbitmq).
step2: Start camunda flow by api(http://localhost:8080/engine-rest/process-definition/key/issue-listener/submit-form)
step3: The flow has a user task called “usertask”
step4: user go to tasklist and complete the task.

My problem is:
My java application will call this flow many times at same time. So there are many tasks in the tasklist and all the task name are “usertask”. I want to change “usertask” to different names. For examples, can I send a process variable as task name when I start the flow by api. So every time I will have a new task name and the name in the tasklist will be different.

Thanks

You could give the task name an expression.
If you called a task

#{taskName}

In runtime it would be named as the value of a variable called taskName

Having an expression works but looks ugly in the modeller. It is possible to change the taskname inside a task-create listener. There is an old but still valid example: https://github.com/camunda/camunda-consulting/tree/master/snippets/task-name-beautifier

2 Likes

Thank you so much. expression works perfectly.

Thanks for your advice. TaskListener is a good way to solve the problem

Please mark the question as “answered” then. Thanks!

Btw.: If it is for single tasks only, it could be modeled right into the bpmn adding a script.
Just add a task listener to the specific user task. Event Type: create,Listener Type: Script, Script Format e.g. “javascript”, Script Type: Inline script and add a single line like:
task.name = "Attention: " + userInput;
where “userInput” contains the dynamic part

1 Like

Hi, i’m looking to implement something similar to what is posted in this thread.

Basically I want to have a task with a dynamic name. A fix part + A dynamic part (coming from one processVariable).
I’m thinking of implementing a task listener script (javascript) but it doesn’t seem to work.
This is my script:
task.name = "This is a dynamic task name: " + target;

A couple of doubts:

  • Should we call the variable “target” or execution.getVariable(“target”) ?
  • What should we enter in the name of the task? Whatever we put here will it be automatically replaced by the task listener or should this be empty?

Thanks,
matias

Hi @matiass,

as both options deliver the same result I prefer the shorter one.

Yes, in your example the assigment will replace the original name. Model your task in a understandable way. You can reuse the original name as well:

task.name = task.name + target;

Hope this helps, Ingo

Hi @Ingo_Richtsmeier thanks for your reply. I tried a few times but with no luck. Does this apply to Manual tasks as well?
Here is a screenshot of a dummy model I have to test this.
The goal is to modify the name of the manual task based on the input variable “var”.
E.g. if var=Matias, then the manual task should be named: “My manual task is called Matias”

When i star the process i get the following error msg. Any ideas what i’m doing wrong?

Thanks!

"message": "Cannot instantiate process definition Dynamic_task_name:5:f3928d7b-7555-11eb-8995-0242ac110002: Unable to evaluate script while executing activity 'Task_0t2okuc' in the process definition with id 'Dynamic_task_name:5:f3928d7b-7555-11eb-8995-0242ac110002':<eval>:1:24 Expected an operand but found var\ntask.name = task.name + var;\n                        ^ in <eval> at line number 1 at column number 24"

Hi @matiass,

task listeners are only available on user tasks and are different from execution listeners.

The changed task name will appear only in the task list and in the history view of the cockpit.

Hope this helps, Ingo