AnsweredAssumed Answered

No process variables if exception is thrown?

Question asked by clstokes on Oct 30, 2013
Latest reply on Nov 5, 2013 by trademak
If an exception is thrown from a service (or script) task, then none of the process variables added during that process are available after it completes. Is this expected?


<?xml version="1.0" encoding="UTF-8" ?>
<definitions id="definitions"
             targetNamespace="http://activiti.org/bpmn20"
             xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:activiti="http://activiti.org/bpmn">

  <process id="ResultAndExceptionTest">

    <startEvent id="start"/>

    <sequenceFlow id="_1" sourceRef="start" targetRef="putValue"/>
    <sequenceFlow id="_2" sourceRef="putValue" targetRef="printValue"/>
    <sequenceFlow id="_end" sourceRef="printValue" targetRef="end"/>

    <scriptTask id="putValue"
                scriptFormat="groovy"
                activiti:async="true">
      <script>
        def map = execution.getVariable( 'references' )
        map.put( 'myValue1', 'asdf' )
        execution.setVariable( 'references', map )
      </script>
    </scriptTask>

    <scriptTask id="printValue"
                scriptFormat="groovy">
      <script>
        def map = execution.getVariable( 'references' )
        map.put( 'myValue2', 'asdf' )
        execution.setVariable( 'references', map )

        throw new IllegalArgumentException("whoops")
      </script>
    </scriptTask>

    <endEvent id="end"/>

  </process>
</definitions>


In this example, neither myValue1 or myValue2 are available via a HistoricProcessInstanceQuery call.

I'm trying to get the process variables with this code below which works fine for a successful completion.

List<HistoricProcessInstance> results = historyService.createHistoricProcessInstanceQuery()
      .includeProcessVariables()
      .processInstanceBusinessKey( context.jobId )
      .list()


Also, what's the best way via the HistoryService (or another service) to determine if a process has failed? endTime is always null for a failed process so I can't tell if it's failed or still going without doing JobQuery to check for an exception message.

Thanks for the help.

Outcomes