2 Replies Latest reply on Apr 17, 2015 11:18 AM by Michael Awizen

    How to connect a disconnected process instance?

    Michael Awizen Novice

      Hi all,

       

      in my test case I'm trying to set a process variable:

       

      // start a new process instance
      Map<String, Object> params = new HashMap<String, Object>();
      
      params.put("userAction", "");
      ProcessInstance processInstance = ksession.startProcess("myProcess", params);
      
      ((WorkflowProcessInstance) processInstance).setVariable("userAction", "deleteAction");
      
      
      

       

      Unfortunately the last line throws the exception:

      java.lang.RuntimeException: Process instance 7[myProcess] is disconnected.

       

      So my question is: how to connect the process instance?

        • 1. Re: How to connect a disconnected process instance?
          Michael Awizen Novice

          The solution was RTFM ;-)

          see: http://docs.jboss.org/jbpm/v6.2/userguide/jBPMBPMN2.html#d0e3731

           

          My actual intention was to modify (or to set) the process variable.

          So this is what works for me now:

           

          ksession.execute(new GenericCommand<Map<String, Object>>() {
          
              @Override
              public Map<String, Object> execute(Context context) {
          
                  KieSession ksession = ((KnowledgeCommandContext) context).getKieSession();
                  org.jbpm.process.instance.ProcessInstance processInstance = (org.jbpm.process.instance.ProcessInstance) ksession.getProcessInstance(id);
          
                  VariableScopeInstance variableScope = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
          
                  Map<String, Object> variables = variableScope.getVariables();
          
                  variableScope.setVariable("userAction", "deleteAction");
          
                  return variables;
              }
          });
          
          
          
          • 2. Re: How to connect a disconnected process instance?
            Michael Awizen Novice

            While the GenericCommand solution works, it is presumably not the preferred way of passing data in a jBPM 6.2 processes.

             

            So I have created an Output Data Mapping in my Task:

             

            odm.PNG

             

            Now in the test class I can pass the value on the task completion.

             

            Map<String, Object> results = new HashMap<String, Object>();
            results.put("userAction", "deleteAction");
            taskService.complete(taskSummary.getId(), "userA", results);
            

             

            And then the variable "userAction" is available for the evaluation in the subsequent split in the process.