9 Replies Latest reply on Nov 19, 2012 8:16 PM by johennes fan

    how to setVariable

    johennes fan Newbie

      Hello,

      After the process was started,I wan't to change the variable.

      Then I use this code:

      ((WorkflowProcessInstanceImpl) ksession.getProcessInstance(processid)).setVariable("aa", "bb")

      But it always call "java.lang.NullPointerException",I don't know why.  The code "getVariable()" works well.

       

       

      Anyone can help me ?

        • 1. Re: how to setVariable
          Mauricio Salatino Master

          Hi,

          Where did you use that code?

          Did you check that the ksession is not null and the process returned from the getProcessInstnace(processId) is not null?

          Cheers

          • 2. Re: how to setVariable
            johennes fan Newbie

            Ksession and ProcessInstance are not null.

            When I use "getVariable()",the result is not null,only the "setVariable()" is the problem.

            • 3. Re: how to setVariable
              Mauricio Salatino Master

              Can you please share the Stacktrace? because if we see the stacktrace we can see where the NullPointerException is happening, if not it can be anywhere.

              Cheers

              • 4. Re: how to setVariable
                Juliano Dantas Newbie

                I have the same problem, but in my case, when I use "setVariable()", process and kruntime are null. I'm using the version 5.2. Look at my stacktrace:

                 

                java.lang.NullPointerException: null

                          at org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:67) ~[jbpm-flow-5.2.0.Final.jar:5.2.0.Final]

                          at org.jbpm.process.instance.impl.ProcessInstanceImpl.getContextInstance(ProcessInstanceImpl.java:127) ~[jbpm-flow-5.2.0.Final.jar:5.2.0.Final]

                          at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.setVariable(WorkflowProcessInstanceImpl.java:238) ~[jbpm-flow-5.2.0.Final.jar:5.2.0.Final]

                 

                Thanks.

                • 5. Re: how to setVariable
                  Juliano Dantas Newbie

                  I've forgotten to comment that I'm using jbpm into Weblogic 11g. Can it be a problem?

                  • 6. Re: how to setVariable
                    johennes fan Newbie

                    I use TOMCAT6(this cannot be changed)+MYSQL+JBPM5.3

                    my stacktrace:

                     

                    java.lang.NullPointerException

                              at org.jbpm.process.instance.impl.ProcessInstanceImpl.getProcess(ProcessInstanceImpl.java:67)

                              at org.jbpm.process.instance.impl.ProcessInstanceImpl.getContextInstance(ProcessInstanceImpl.java:127)

                              at org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl.setVariable(WorkflowProcessInstanceImpl.java:238)

                     

                    it is the same of Juliano Dantas's

                    • 7. Re: how to setVariable
                      johennes fan Newbie

                      And my code :

                       

                      HornetQHTWorkItemHandler hornetQHTWorkItemHandler = new HornetQHTWorkItemHandler(ksession);

                      ksession.getWorkItemManager().registerWorkItemHandler("Human Task", hornetQHTWorkItemHandler);

                      WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl)ksession.getProcessInstance(processid);

                      pi.setVariable(param, values);

                      • 8. Re: how to setVariable
                        Juliano Dantas Newbie

                        I think this can help you:

                         

                        public void setVariable(Long processInstanceId, String nome, Object value) {

                               TransactionManager transactionManager = jBpmConfiguration.getTransactionManager();

                               try {

                                    transactionManager.begin();

                                   

                                    RuleFlowProcessInstance processInstance = (RuleFlowProcessInstance) JBpmConfiguration.getInstance().getKnowledgeSession().getProcessInstance(processInstanceId);

                                    processInstance.setVariable(nome, value);

                                   

                                   transactionManager.commit();

                                } catch (Exception e) {

                                    logger.error(e.getMessage());

                                }

                        }

                        • 9. Re: how to setVariable
                          johennes fan Newbie

                          Thanks, I have got the solution what is the same with yours.It really caused by the Transaction.