5 Replies Latest reply on Dec 11, 2015 3:40 AM by jimmy001

    How to access e.g. startdate from Script Task?

    jimmy001 Apprentice

      Hello everybody,

       

      I would like to access ProcessInstanceInfo.startdate or another variable, where the creation timestamp of the currently executed processinstance is located, within a script task.

      How can this be done?

       

      Thx for  your help.

        • 1. Re: How to access e.g. startdate from Script Task?
          Abhijit Humbe Master

          You can try with below code:

           

          org.jbpm.process.instance.impl.ProcessInstanceImpl p = (org.jbpm.process.instance.impl.ProcessInstanceImpl)kcontext.getProcessInstance();

          org.jbpm.process.audit.ProcessInstanceLog log = (org.jbpm.process.audit.ProcessInstanceLog) p.getMetaData().get("ProcessInstanceLog");

          System.out.println("Start Date:"+log.getStart());

           

          Similarly you can print user who started processinstance, and other details.

          1 of 1 people found this helpful
          • 2. Re: How to access e.g. startdate from Script Task?
            jimmy001 Apprentice

            No, the map doesn't contain an element with the matching key. The only entries I could find in the code are:

             

            subprocessnode:

            ((ProcessInstanceImpl) processInstance).setMetaData("ParentProcessInstanceId", getProcessInstance().getId());

            ((ProcessInstanceImpl) processInstance).setMetaData("ParentNodeInstanceId", getUniqueId());

            ((ProcessInstanceImpl) processInstance).setMetaData("ParentNodeId", getSubProcessNode().getUniqueId());           

             

            startInstance:

             

            ((ProcessInstanceImpl) processInstance).setMetaData("ParentProcessInstanceId", parentProcessInstanceId);

            • 3. Re: How to access e.g. startdate from Script Task?
              Abhijit Humbe Master

              Can you specify what exactly you are trying to print from Script Task. Code snip provided in above comment will print date and time when process instance is started like as:

              ~~~

              INFO  [stdout] (http-localhost.localdomain/127.0.0.1:8080-5) Start Date:Wed Dec 09 20:00:13 IST 2015

              ~~~

              • 4. Re: How to access e.g. startdate from Script Task?
                jimmy001 Apprentice

                I have checked the code base and verified, that the lines you posted work, if you use them before the first human task.

                This is because in "JPAWorkingMemoryDbLogger.beforeProcessStarted" the following line is executed:

                 

                ((ProcessInstanceImpl) event.getProcessInstance()).getMetaData().put("ProcessInstanceLog", log);

                 

                Otherwise the following line is executed (e.g. beforeNodeTriggered):

                 

                NodeInstanceLog log = (NodeInstanceLog) ((NodeInstanceImpl) event.getNodeInstance()).getMetaData().get("NodeInstanceLog");

                • 5. Re: How to access e.g. startdate from Script Task?
                  jimmy001 Apprentice

                  I ended up by overriding beforeNodeTriggered in a custom audit logger and put it into the metadata map.

                  Thx