[jboss-user] [jBPM] - getVariable and setVariable

minslay minslay do-not-reply at jboss.com
Mon Dec 3 07:33:39 EST 2012

minslay minslay [https://community.jboss.org/people/minslay] created the discussion

"getVariable and setVariable"

To view the discussion, visit: https://community.jboss.org/message/779611#779611


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???

Reply to this message by going to Community

Start a new discussion in jBPM at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20121203/4c96ea00/attachment-0001.html 

More information about the jboss-user mailing list