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"

  <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"
        def map = execution.getVariable( 'references' )
        map.put( 'myValue1', 'asdf' )
        execution.setVariable( 'references', map )

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

        throw new IllegalArgumentException("whoops")

    <endEvent id="end"/>


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()
      .processInstanceBusinessKey( context.jobId )

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.