My FNZ Studio Version

Processes

Latest Update: 10.02.2022 |
Recipe
2024
2023
2022.2
2022.1
11
10
9
8
7

Problem

I'm building a reassign functionality in the Appway Portal that allows the owner of a task to reassign it to another user. I used the AssignWorkitemToUser out-of-the-box function, but I have an issue when I use it for my process.

The reassignment seems to work at first: the target user receives the task I reassign to that user, and is able to work on it. When the user clicks the Next button in the Screen, however, and moves the Token to the next activity in the same Swimlane, the Token is assigned to the previous owner (me).

How can I build a script which takes care of reassigning the owner of a Workitem, and prevents the issue mentioned above?

Solution

The issue described above occurs due to the out-of-the-box function in Appway that assigns the specified Token to the specified User (AssignWorkitemToUser). This function does not update the Swimlane expression of the Swimlane the token is currently in automatically: the developer must tell the function how to update the Swimlane expression.

As a result, when a developer just uses the function defaults: 

  1. The current token is reassigned to the target specified user.
  2. When the new user clicks Next and advances the token to the next Screen in the same Swimlane, the Swimlane participant expression is re-evaluated and the token is reassigned to the previous owner.

The variableAssignments parameter

The AssignWorkitemToUser function provides an optional parameter called variableAssignments. This parameter lets you assign some variables in the target Process Value Store to update the Swimlane participant expression. The behavior of this additional parameter differs between versions of Appway.

Usage

This optional parameter can be used to set any number of variables in the target Process Value Store. This can also be done by evaluating an expression passed as an input to the function, which is going to be recognized and evaluated in the context of the target Value Store.

For the projects running on these versions of Appway, the suggested implementation is the following:

Function ReassignOwner(String $workitemId, String $forwardUserId, String $workflowInstanceId := '') : Nothing Begin
   Workitem $workitem;
   If EMPTY($workflowInstanceId) Then
      $workitem := WORKITEM($workitemId);
   Else
      $workitem := WORKITEM($workitemId, $workflowInstanceId);
   End
   If $workitem != null Then
      String $theWorkFlowId := $workitem.getWorkflowId();
      String $oldUserId := $workitem.getUserId();
      String $swimlaneName := $workitem.getSwimlaneName();
      Local Named Any $map;
      $map := {}:Any;
      If $forwardUserId != $oldUserId Then
         String $ownerExpression := GetParticipantUserExpression($workitem);
         If $ownerExpression!= null && STARTSWITH($ownerExpression, '$') Then
            $map[$ownerExpression] := $forwardUserId;
            AssignWorkitemToUser($workitemId, $forwardUserId, $map, true);
         End
      End
   End
End

Where the function GetParticipantUserExpression is implemented as follows:

Function GetParticipantUserExpression(Workitem $workitem) : String Begin
   If $workitem == null Then
      Return null;
   End
   String $expression := $workitem.getParticipantUserExpression();
   If $expression == null Then
      String $workflowInstanceId := $workitem.getWorkflowInstanceId();
      WorkflowToken $parent := ProcessToken($workitem.getTokenId(), $workflowInstanceId).getParentWorkflowToken();
      If $parent == null Then
         Return null;
      Else
         Return GetParticipantUserExpression(WORKITEM($parent.getId(), $workflowInstanceId));
      End
   Else
      Return $expression;
   End
End

IMPORTANT!
Regardless of which version of Appway you are using, the functions provided only work correctly if there are no parallel activities in the current Swimlane.

If the Swimlane has parallel tasks (i.e. multiple Tokens), using the function results in an update of the Swimlane participant expression — which updates the ownership of all the Tokens in the Swimlane as soon as they are "moved" in the Swimlane context. There isn't a satisfactory solution to this issue beyond splitting up the Swimlane, or making sure it is OK that all the tokens are reassigned simultaneously.

© 2026 Appway AG. All Rights Reserved