3 Replies Latest reply on Aug 26, 2014 2:07 PM by samboy_05

    Set ProcessVariables on a running processInstance over RemoteAPI -jBPM 6.0.1

    samboy_05

      Hi ,

      Apart from supplying processVariables when begining a process ,we used to be able to set process variables for  processInstances which is already running using the GenericCommands like :

       

      Map<String, Object> variables = ksession.execute(new GenericCommand<Map<String, Object>>() {
          public Map<String, Object> execute(Context context) {
              KieSession ksession = ((KnowledgeCommandContext) context).getStatefulKnowledgesession();
              org.jbpm.process.instance.ProcessInstance processInstance = (org.jbpm.process.instance.ProcessInstance) ksession.getProcessInstance(piId);
              VariableScopeInstance variableScope = (VariableScopeInstance) processInstance.getContextInstance(VariableScope.VARIABLE_SCOPE);
              Map<String, Object> variables = variableScope.getVariables();
              return variables;
          }
      });
      

       

      How do we do the same when using RemoteAPI over REST ? I checked the REST calls in the documentation but I didn't find any for setting variables in processInstances which are already running.

       

      If I use the above mentioned code , I get the exception :

      java.lang.UnsupportedOperationException: The .execute(..) method is not supported on the remote api.

       

      salaboy21 can you help ?

        • 1. Re: Set ProcessVariables on a running processInstance over RemoteAPI -jBPM 6.0.1
          salaboy21

          Can you try that in jbpm 6.1.0.Final? to see if that's available there?

          By the way.. why do you want to set the process variables from outside the process? that's supposed to be something internal that the activities inside the process will change.

           

          HTH

          • 2. Re: Set ProcessVariables on a running processInstance over RemoteAPI -jBPM 6.0.1
            samboy_05

            salaboy21 , Thanks for your quick response ,

             

            However , as per my experience , most of the processes I have made are not totally deterministic in nature , lets take an XOR node after a human task . The human when completing the task , provides the decision based on which the XOR fork will determine the path the process flow takes.

             

            In such cases I have to supply an external variable to the process. Do I have a choice ?

             

            PS : There is no explicit way described to set the variables , can use Execute Calls instead ??

             

            + krisverlaenen

            • 3. Re: Set ProcessVariables on a running processInstance over RemoteAPI -jBPM 6.0.1
              samboy_05

              Got it running .

               

               

              public Object execute(Command<?> command){
                   CommandBasedStatefulKnowledgeSession session = (CommandBasedStatefulKnowledgeSession)ksession;
                   return session.execute(command);
                }
              
              public void setProcessVariables(Long processInstanceID, String key, Object value) {
                   Map<String,Object> hashMap = new HashMap<>() ;
                   hashMap.put(key, value);
                   SetProcessInstanceVariablesCommand setVariables = new SetProcessInstanceVariablesCommand(processInstanceID,hashMap);
                   try{
                execute(setVariables);
                   }catch(Exception ex){
                log.error(ex);
                   }
                }