Reassign a user task | Change Assignee

Hello everybody,
I would like to change the assignee of a user task.
The following conditions are given.
User A gets assigned to the Usertask1 (“Fehler lösen”) . User A knows that User B has to fulfill the Usertask1, so User A should assign UserB to this Task.
Changing the Assgnee with the assigneefield on the top of the Form is no Option, cause nobody Knows all the Usernames and I dont want to grant the user authorization to change fields at the Top.
My Idea is to Create an dropdown field in the form where User A can choose the new assignee.
If this field is not null, there will be a service Task which changes the variable which is for the assignee.

The problem in conclusion my way doesnt Work.
Does anybody know a good way to handle?

2022-07-13 12_43_54-Camunda Modeler

Best regards!

Hey @photowinget,

Could you share your diagram and your code? Could you define a little bit more in detail what “does not work” mean? Do you get an error, or is it just not assigning the new person?

Kind regards
Nele

Hello Nele,
thanks for your response. I try to explain my situation better.

My target is to get a dropdown box which lists the possible users after that i would like to update the User Task and assign the new user to the task

I tried different solutions.
First I tried to add a tasklistener at the update Event with the following Code and Diagramm (first_try.bpmn)
first_try.bpmn (3.7 KB)
I didn’t get an error but i can’t submit the Form anymore.

task.setAssignee(task.getVariable('newassignee'));

The second try was to create set the variable newassigne to assigne during a servicetask and update the assignee from the User task with an execution listener at start event.
second_try.bpmn (5.8 KB)
Then i got this error:
Cannot instantiate process definition UserAssign_Test:6:a2f402d6-0379-11ed-8fdc-00155d1e728a: Unable to evaluate script while executing activity ‘Activity_03g2wgr1’ in the process definition with id ‘UserAssign_Test:6:a2f402d6-0379-11ed-8fdc-00155d1e728a’:ReferenceError: “assignee” is not defined in at line number 1

Is there a generel recommend way to change the assignee of an existing user task?

Hello everyone
Does anyone know if it is possible to change the assignment of a user task with the rest of the service? Is it possible to call the rest service from an embedded form? I don’t know Javascript and cam-script that well? Does anyone know a solution? I am grateful for any help!

Hi @photowinget,

you can use this REST Api to set the assignee of a user task: Set Assignee | docs.camunda.org.

Hope this helps, Ingo

Hello Ingo,
thanks for your response. I tried your solution, but now my tasks only gets unclaimed. The newassignee doesn’t get assigned. Do you have an idea whats my issue?
Thanks a lot!

<form>
  <div class="form-group">
    <label class="control-label col-md-4" for="newassignee">Neuzuweisung an:</label>
    <div class="controls">
      <select cam-variable-name="newassignee" cam-variable-type="String" class="form-control" id="newassignee">
        <option>---</option>
        <option>user1</option>
        <option>user2</option>
        <option>user3</option>
        <option>user4</option>
      </select>
    </div>
  </div>

  <script cam-script type="text/form-script">
  inject(['$http', 'Uri', function($http, Uri) {
  camForm.on('variables-stored', function() {
        var Taskid = camForm.taskId;
        var variableManager = camForm.variableManager;
        var newassignee = variableManager.variableValue('newassignee');
        if(newassignee === '---')
        {
          alert("keine neuzuweisung");
        }
        else
        {
          alert("Der Task: " + Taskid +" wurde dem Benutzer: " + newassignee +" zugewiesen.");
          $http.post(Uri.appUri('http://hostname:8080/engine-rest/task/' + Taskid + '/assignee'), { headers: { 'Content-Type': "application/json;charset=utf-8"},body: 'userId': newassignee } );
        }
    });
}]);
</script>


</form>