2 Replies Latest reply on Dec 18, 2013 4:44 AM by swiderski.maciej

    Problem in reading Process Varibles after process is completed???

    javalearner

      Hi,

      I am setting up few process variables in ExitAction of Human Task node. I need those values after task completion.

      I am able to get the those values till process is active.

      But unable to get the process variables after process gets completed.

      I tried 3 different ways,

      1)

      Map<String, Object> variables = ksession.execute(new GenericCommand<Map<String, Object>>() {

          public Map<String, Object> execute(Context context) {

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

          }

      });

       

      Above approach is giving only when the process is active.

       

      2)

      After I tried to get the variables from VariableInstanceLog.I am using a DTO object as process variable. So when I looked at the value column of VariableInstanceLog table, it is Varchar. means all the values are stored as Strings.

      Please suggest me how do I get the Object from VariableInstanceLog table.

       

      3)

      I tried to get the values using ContentMarshallerHelper by passing taskId. From this, I am able to get the state of the variables as the state when I passed them to completeTask. but I want the changes that I made in Exit Action .

       

      Please suggest me on this.

       

      Thanks,

      Rajesh.

        • 1. Re: Problem in reading Process Varibles after process is completed???
          quangtin3

          Hi Rajesh,

           

          I have the same result with the approach 1st. I think it's as designed because we're dealing with Knowledge Session. In our system, we're using approach 2nd, I will be a bit more detail here:

          • To keep the jBPM engine small and running without much additional tables, we successfully managed to have almost all business states passing between nodes, rules, tasks, service tasks using only jBPM's parameter mechanic (Task Variables, Process Variables).
          • For example, to support multiple file attachments we only passing the file IDs as Task parameters.  We're using a separate File Repository module with an interface some things like those:
          public VogAttachmentWrapper load(Integer id) { .. }
          public Integer store(UploadedFile file){.. }
          
          
          • Using a custom made Task Form (Primefaces Extenstion's DynaForm), so It's a trivial task to display the Attachments (Preview, Download) with just the IDs.

          I think We did try to pass a POJO object itself as a Process Instance Variable (when starting the process) but I just can't recall the result. I will find sometime to check the User Guide and orange an experiment.

           

          In your approach 3th, to make the change in Exit Action persist, we need to assign it value to a Process Variable. Task Service, or Human Task in particular are simply separate engine from jBPM.

           

          For your question hasn't had any response in 4 day, so maybe this might be help.

          • 2. Re: Problem in reading Process Varibles after process is completed???
            swiderski.maciej

            that is expected behavior as process instance contains variables as long as it is active, once it's completed there will not be access to process variables as instance that owned them does not exist any more. As you noticed, VariableInstanceLog holds the value of variables although it's string only. So I would suggest to implement toString() method in your process variable objects that then can be read and used to create an instance of that object. For example use json to serialize it on to string and thus you would be able to recreate a readonly view of the object. json is just an example but you can use any type of format.

             

            HTH