[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

--------------------------------------------------------------
Hello,

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
                    processParameters.put("result",5);

                    factoryP1.name("Process1").version("1.0").packageName("org.jbpm") 
                              .imports("java.util.HashMap")


                              // creating a new var
                              .variable("resultReceived", new ObjectDataType("java.lang.Integer"))

                                        .startNode(1).name("Start").done()
                                        .actionNode(2).name("Action")
                                        // 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.
                                        .actionNode(3).name("Action")
                                        .action("java","System.out.println(\"Another Node \");").done()
                                        .endNode(4).name("End").done()
                                        // Connections
                                        .connection(1, 2)
                                        .connection(2, 3)
                                        .connection(3, 4);

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

                    kbuilder.add(ResourceFactory.newByteArrayResource(
                                        XmlBPMNProcessDumper.INSTANCE.dump(process1).getBytes()),
                                        ResourceType.BPMN2);

                    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
[https://community.jboss.org/message/779611#779611]

Start a new discussion in jBPM at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

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