How to change the userTask's name according to process variables

Hi
I want to when the edit is equal to yes and the process will return to “registerTask”, the name of “registerTask” will be changed to another name something like “returnedTask”.
How can I do this?

1

Hi @rezza72

Use expression like ${taskTitle} in the name property of the task. So you can set “taskTitle” variable with the Intended name.

1 Like

@mrdavoodi64
Thanks for your answer.
How can I set that?
Should I create a task listener and then set that?
If so, could you guide me to creating the task listener?

You can do it via script task or task listener.
the command in script task is : execution.setVariable(“taskTitle”,“yourDesiredTitle”);

and in task listener : task.execution.setVariable(“taskTitle”,“yourDesiredTitle”);

1 Like

I set the usertTask’s name: ${taskTitle}

Then I created a script task which has this script:
${edit == 'true' ? task.execution.setVariable("taskTitle","test1") : task.execution.setVariable("taskTitle","test2")}

but I faced this error:

Unknown property used in expression: ${taskTitle}. Cause: Cannot resolve identifier ‘taskTitle’

I don’t know what can I do.

taskTitle should be defined before reaching the related task. Then in the gateway expression you can change it.

1 Like

the related task is the first task which has the taskTitle name.
I defined taskTitle in the first task as a form but I still have the problem…

please share your bpmn model

Sorry for taking your time.

here you are:
sample.bpmn (7.3 KB)

@rezza72 You need to set the dynamic task name before the usertask creation, that is in Start Event itself. Currently you’re setting task name in the user task itself with executing the groovy script. One pitfall here is the task name won’t be set because all the execution data on the usertask will be in-memory and will be persisted at the next save point. So if you handle the assigning task name in the start event or take listener of the outgoing sequence flow from start event will set the dynamic task name, why because the user task has the default save point ie., waiting state.

1 Like

Thank you very much for your complete guidance.
But actually, I don’t want to set the name of the userTask myself.
I want userTask name to be changed based on the value of a variable in the editTask.
Actually, I want in the first, the userTask’s name to be “registerTask” and then if the “edit == true”, the first userTask’s name changed to something like “test1” and when the “edit == false” the first userTask’s name don’t be changed (still “registerTask”). And I have nothing to do with determining that’s name.

Then you need to set the task name in the take listener of the sequence flow based on the flag edit==true

It didn’t work.
I really messed up and confused…
Could you please see this bpmn?

sample.bpmn (7.4 KB)

I’ll be thankful

Maybe I explained unclearly.
All I want is to rename the “registerTask” if the edit == true.

1

I don’t think this is an unreasonable question.

I’m still dealing with this issue.
Please guide me.

Hi @rezza72,

the easiest way is to use a task listener on the create event and use the name attribute of the provided task object.

For example:

    <bpmn:userTask id="Activity_02328bn" name="${taskTitle}" camunda:assignee="${prc_starter_user_uri}">
      <bpmn:extensionElements>
        <camunda:taskListener event="create">
          <camunda:script scriptFormat="javascript">task.setName("Hallo Rezza");</camunda:script>
        </camunda:taskListener>
      </bpmn:extensionElements>
    </bpmn:userTask>

To add additional logic, surround the statement with if-then-else. And choose the scripting language (or Java) you like most.

Hope this helps, Ingo

1 Like

Thanks a lot.
With your guidance, I got so closer to what I wanted…
Now, when I statically set the value of the variable in the script (edit = true or edit = false), the condition is executed and the renaming of the userTask is worked.

This is the script:

var edit;
if (edit == 'false') {
  task.setName("test1");
}else{
  task.setName("test2");
}

But I still have a problem.
I must set the variable (edit) before entering the task user.
In fact, two flows are connected to userTask.
I want the set one of the flows with “true” value and set another with “false” value.

To do this, I created a script in the Listener section of each flow and put this script inside the script section:
var edit = 'false';

But this didn’t work. and edit variable set by “null” value.

Could you please help me to solve this problem too?

Thanks in advance.

Hi @rezza72,

please try execution.setVariable("edit", false) instead of var edit = 'false'.

Hope this helps, Ingo

1 Like

Unfortunately, it made no difference :((
I used execution.setVariable("edit", false) exactly instead of var edit = 'false' in the script section of Listener tab of flow.

Hi @rezza72

This is your desired model.
sample.bpmn (7.5 KB)

1 Like