5 Replies Latest reply on Sep 5, 2006 5:16 PM by stibrian

    passing data to AssignmentHandler best practice?

    jmjava

      I would like to have the ability to assign tasks to users based on GUI input. I see where you can use an assignment expression to do this but I'm not clearn on how to pass data to the scripting environment.

      For instance if i want don't want to hardcode this assignment





      How should i do this? Is it as simple as setting variables on the taskInstance and using the script to retrieve them?

      -jm

        • 1. Re: passing data to AssignmentHandler best practice?
          kukeltje

          Yes, or retrieve them in a special assignmenthandler, or from your own database or in an actionhandler or whatever. It is indeed that simple. Great isn't it :-)

          • 2. Re: passing data to AssignmentHandler best practice?
            jmjava

            thanks ron i am having trouble with the syntax:


            taskInstance.setVariable("buyer", "cookiemonster");
            taskInstance.setVariable("salesman", "ernie");
            taskInstance.setVariable("accountant", "bert");
            taskInstance.setVariable("shipper", "grover");


            i want to be able to access these variables in script and i am trying:


            <assignment expression="taskInstance.variables['salesman']" />



            <assignment expression="taskInstance.variables['accountant']" />



            <assignment expression="taskInstance.variables['shipper']" />


            but i'm getting this error: couldn't resolve assignment expression 'taskInstance.variables['salesman']'

            I have been reading the beanshell pdf put it's not helping much. any ideas?

            • 3. Re: passing data to AssignmentHandler best practice?
              kukeltje

              Please use the [ c o d e ] tags without the spaces around your xml. Use preview to see the result.

              You cannot use beanshell in the expression. Look at the jbpm docs and more important the testcases to see how you should use this.

              • 4. Re: passing data to AssignmentHandler best practice?
                jmjava

                FWIW I got it:

                Instead of hardcoding the assignment like in the base websale example i changed the process Defintion to be:


                <swimlane name="salesman">
                 <assignment actor-id="#{taskInstance.variables['salesman']}" />
                 </swimlane>
                
                 <swimlane name="accountant">
                 <assignment actor-id="#{taskInstance.variables['accountant']}" />
                 </swimlane>
                
                 <swimlane name="shipper">
                 <assignment actor-id="#{taskInstance.variables['shipper']}" />
                 </swimlane>


                and after i create my processInstance i set the taskInstance variables in java code:

                // create a new taskinstance for the start task
                 TaskInstance taskInstance = processInstance.getTaskMgmtInstance().createStartTaskInstance();
                
                 taskInstance.setVariable("buyer", "cookiemonster");
                 taskInstance.setVariable("salesman", "ernie");
                 taskInstance.setVariable("accountant", "bert");
                 taskInstance.setVariable("shipper", "grover");


                this allows me to assign the swimlane actors via business logic instead of hardcoding them.



                -jm

                • 5. Re: passing data to AssignmentHandler best practice?
                  stibrian

                  using the names of the swimlanes and a custom assignment class is another trick that works well for me.
                  Or using a "named user" that is stored in the process as a variable and then again using swimlane name as a key into which one you want - nearly no code, but nice flexibility.