2 Replies Latest reply: Jul 10, 2012 4:06 AM by knevik RSS

kcontext.setVariable("variable",value) for begin used by following tasks?

gigazhang Newbie

my flow:

12345.png

 

every node i set  #{userid} as actorid

 

start process:

 

Map<String,Object> params = new HashMap<String, Object>();

params.put("userId", "Jack");

ksession.startProcess("com.test.task.bpmn",params);

 

 

the problem is when the first task completed,how can i change the variable userId to set the follow actor?

 

how can i get the kcontext to set variable by ksession?

  • 1. Re: kcontext.setVariable("variable",value) for begin used by following tasks?
    Mauricio Salatino Master

    What are you trying to achieve? Usually that's not something that you want to do. The business process is defined by business analyst who assign people or groups to their tasks.

    Do you really need to do that assignment using just one variable? I mean. you can.. but it sounds odd and not really representative for a real use case.

    You can use on-entry and on-exit actions to change that variables from your nodes.. but once again.. I don't really recommend going in that direction, not because you can't but you probably don't want to do that in the long run.

     

    Cheers

  • 2. Re: kcontext.setVariable("variable",value) for begin used by following tasks?
    knevik Newbie

    if you do want to set a variable in the workflow use the following code

     

    kcontext.setVariable("userId", "user");    //where userId is the variable name and user is the name of the user

     

    this can be put in either a script task of its own, or in the on-entry or on-exit event of another task

     

    <userTask id="_5" name="Human Task" >

          <extensionElements>

           <tns:onEntry-script scriptFormat="http://www.java.com/java">

            <script>

             kcontext.setVariable("userId", "user");

            </script>

           </tns:onEntry-script>

          </extensionElements>

          <ioSpecification>

              ...

    </userTask>