1 Reply Latest reply on Jul 11, 2013 12:32 PM by antmendoza

    How to get Process Instance Variables from Ksession.getProcessInstance(..) ?

    Thomas Setiabudi Expert

      Hi,

       

      How do we get variables of a Process Instance if we get the process instance from kssession?

       

      In this discussion

      https://community.jboss.org/message/753997

       

      it says to get the variable instance this way

      VariableScopeInstance variableScope = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);

                                              Map<String, Object> variables = variableScope.getVariables();

       

      where processInstance is org.jbpm.process.instance.ProcessInstance

       

      While this is what I do:

      org.jbpm.process.instance.ProcessInstance processInstance = (org.jbpm.process.instance.ProcessInstance) ksession.getProcessInstance(processInstanceId);

       

       

      ksession.getProcessInstance(..) returns org.drools.runtime.process.ProcessInstance

       

      can I just convert it that way?

       

      Currently my problem is processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE); always return null eventhought the processInstance is not null.

       

      Regards,

      Thomas Setiabudi

        • 1. Re: How to get Process Instance Variables from Ksession.getProcessInstance(..) ?
          antmendoza Newbie

          Hi Thomas,

          I have tested  https://community.jboss.org/message/753997 and I hadn't any problem.

           

          Before I know this solution, I used to cast processInstance to org.jbpm.workflow.instance.WorkflowProcessInstance.

              

              

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

                    varMap.put("variable", "test");

           

                    org.drools.runtime.process.ProcessInstance processInstance = ksession.createProcessInstance(

                                        processId, varMap);

           

                    org.jbpm.workflow.instance.WorkflowProcessInstance workflowProcessInstance = (org.jbpm.workflow.instance.WorkflowProcessInstance) processInstance;

                    String varValue = (String) workflowProcessInstance.getVariable("variable");

           

                    Assert.assertEquals("test", varValue);


          1 of 1 people found this helpful