0 Replies Latest reply on Dec 3, 2012 7:33 AM by minslay minslay

    getVariable and setVariable

    minslay minslay Newbie



      I'm newbie with jBPM and I'm stuck with something I think it's easy but it doesn't work.


      I'm trying define a process dynamically with Process API. I want to insert a variable into my actionNode so, I create a HashMap and I use kcontext.getVariable().

      Now I get my variable into my actionNode and I can use it.

      Then I want to modify (or create a new variable) my variable and its value. I don't know how to modify it and use kcontext.setVariable(); also I dont know how to recover that value in my java code.


      Here my code



                          HashMap<String, Object> processParameters = new HashMap<String, Object>(); 

                          KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

                          RuleFlowProcessFactory factoryP1 = RuleFlowProcessFactory.createProcess("org.jbpm.Process1");


                          // My variable and value





                                    // creating a new var

                                    .variable("resultReceived", new ObjectDataType("java.lang.Integer"))




                                              // I receive my variable from java Code with kcontext.getVariable

                                              // and modify its value (now:6)

                                              .action("java",          "resultReceived = (Integer) kcontext.getVariable(\"result\")+1;" +

                                                                  "System.out.println(resultReceived);" +

                                              // I put my new variable with kcontext.setVariable

                                                                  "kcontext.setVariable(\"resultReceived\", resultReceived);").done()

                                              // another actionNode.


                                              .action("java","System.out.println(\"Another Node \");").done()


                                              // Connections

                                              .connection(1, 2)

                                              .connection(2, 3)

                                              .connection(3, 4);


                          RuleFlowProcess process1 = factoryP1.validate().getProcess();






                          KnowledgeBase kbase = kbuilder.newKnowledgeBase();

                          StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

                          ProcessInstance processInstance = ksession.startProcess("org.jbpm.Process1",processParameters);


                          // and now... How can I get resultReceived from actionNode???