2 Replies Latest reply on Feb 27, 2006 2:30 PM by osama Abdel-Karim

    Script element in Join Node

    osama Abdel-Karim Newbie


      According to the code of Join Node, you can specify a scirpt that evaluates to a boolean value, so that when a token reaches the join node, JBPM executes the script and activates the parent token when the script evluates to true.

      My question is: How can I add this script to the Join? There is no child element for the Join node named Script in the schema.

      Another question: How can I make the script returns/evaluates to a boolean value.

      Thank you

      P.S. I use JBPM 3.0

        • 1. Re: Script element in Join Node
          Alejandro Guizar Master

          Joining with a script is an experimental feature. Its definitive shape has not been decided yet. That's why you don't see a related item in the jPDL schema.
          If you want to play with this feature, you can set the script programatically, with something like this:

          // retrieve the join node from the process definition
          Join join = (Join) processDefinition.getNode("myjoin");
          // configure a join condition
          Script condition = new Script();
          condition.setExpression("threshold > 3");

          Be aware that this feature might undergo significant changes or be completely removed, so don't rely on it. Please help us by describing what is your use case and any additions you'd like to see.

          • 2. Re: Script element in Join Node
            osama Abdel-Karim Newbie

            Thank you for your reply, unfortunatley, the code didn't work.

            In the source code join, the following is written:

            Object result = script.eval( token );
            } else if ( result instanceof Boolean ) {
             // the boolean specifies if the parent needs to be reactivated
             reactivateParent = ((Boolean)result).booleanValue();

            I think that the If condition will never be invoked since script.eval returns Map data type.
            I checked the condition code of Decision node and found that they simulate return statement by adding dummy return variable and then check the value of this variable after evaluating the script. I think somthing like this could be done easily in join node. Let me know if I missed something.

            About the use case, we want to model the process of requesting a holiday. The requester (an employee) should get the approval of at least two other employees (out of 4) to be responsible for his work during the holiday.

            So, we thought of the following. A fork will send the holiday request to the 4 employees (4 waiting-states). Then on enter event of the join, the number of approvals and the number of refusals are calculated (which are found in the process variables) in a script. We want to write a condition like this in Join script:
            (approvals >=2) or (refusals>2)

            This should be a sufficient condition to reactivate the parent; notice that we needn't wait for the reply other employees if two of them accepted. Following the join, there should be a decision node that decides whether to continue the process or reject the request based on the values of Approvals and Refusals.

            Let me know if this could be modeled in another way. We want to give the user the ability to design his own workflow, so writing dedicated classes won't be suitable.

            Thank you.