Search code examples
flowable

How to assign string identifiers selected in form to sub-processes in Flowable 3.6.1?


I've checked this topic : https://forum.flowable.org/t/how-to-assign-as-sub-process-initiators-users-groups-that-have-been-selected-in-a-form/1429 but its answer had not been verified (and I could not verify it neither).

What I want to do is just build a simple process with dynamic numbers of sub-processes which assignee will be specified dynamically according to the choices made in start form. Actually, the number of sub-processes is exactly same as selection in start form. For example, I've choose 3 user identifiers of A,B,C, and there will be 3 sub-processes that one assigned to A, one assigned to B and another assigned to C.

However, after a long time trying, I found the identifier string "A"(same as B and c) has only be treated as a TextNode and the assignee is a string identifier '"A"' not the real identifier 'A'. When I debugged my flowable installation, I evaluated at source code JsonIndexVariableType#setValue and built a new ObjectNode with : {"jsonValue":{"id":"A"} and it finally show me the exactly user A in sub-process instance.

I'm eager to know the practical method to achieve this goal, any help would be appreciate.


enter image description here enter image description here


Solution

  • After a lot of repeated attempts, I finally found the solution to achieve this goal. The solution is simple, just put ${user.textValue()} instead of ${user} to extract the real assignee identifier from a TextNode.

    REMEMBER, the variable is not a pure string value, it is actually an instance of TextNode, which means toString() method will return ""<id>""(double quote result in failure of finding a proper assignee).


    The source code is located at :

    org.flowable.engine.impl.bpmn.behavior.UserTaskActivityBehavior#handleAssignments( TaskService taskService, String assignee, String owner, List<String> candidateUsers, List<String> candidateGroups, TaskEntity task, ExpressionManager expressionManager, DelegateExecution execution, ProcessEngineConfigurationImpl processEngineConfiguration)


    Another way to do this is using Script Task, Groovy script for example:

    execution.setVariable("user", user.textValue())
    

    Then you can assignee to ${user} (user here is already pure string, this is different from former solution).