isBranchingTask

A default task has one end state. By adding the option “isBranchingTask” this behavior is overridden to make it possible to add as many as needed.

Version

Description Changed / added in version
First released 3.0.X
Added IState variant 3.1.0
Added to PR 3.1.0

Default Behavior

  • By default statuses are configured in the database. They are stored in the table StateTask of the workflow component.
  • If no extra end state is configured in the custom code, then the default end state will be used.

Different branching task implementations

The TaskResult class provides a method to override the default end state.

TaskResult.branchSuccess();

This method has multiple overloaded variants:

TaskResult.branchSuccess();
TaskResult.branchSuccess(IState state);
TaskResult.branchSuccess(T value);

The behavior of this method changes depending on the chosen implementation.

Different behaviors

No value passes to the method

If no value is passed to the method, an extra modify step is needed in the custom code to override the end state. The workflow will detect the branchSucces result and refrain from setting the end state.

In this case, it is expected that the end state is set in the custom code.

Example

try {
  // ...

  ExampleDetails exampleDetails = new ExampleDetails();
  exampleDetails.setStatus("someState");

  exampleAgent.modify(exampleDetails);

  return TaskResult.branchSuccess();
} catch(Exception e) {
  // ...
}

An IStateDef class is passed to the method

If an instance of the interface IStateDef is passed to the method, the end state of the task will update automatically to the end state described by the IStateDef instance. Typically, this instance is provided by the Data State enum

Example

try {
    // ...

    return TaskResult.branchSuccess(ExampleState.SOME_STATE);
} catch(Exception e) {
  // ...
}

A value different from an IStateDef class

Attention: The following construction can only be used if the option “hasResultClass” is active on this task.

If a value different from an IStateDef class is passed to the method, it has no influence on the end state. The value that is passed is the return value of the task. An extra modify step is needed in the custom code to override the end state.

This is actually a variant of ‘No value passes to the method’ combined with the option ‘hasResultClass’

Example

try {
    // ...

    SomeResultClass someResultClass = new SomeResultClass();

    ExampleDetails exampleDetails = new ExampleDetails();
    exampleDetails.setStatus("someState");

    exampleAgent.modify(exampleDetails);

    return TaskResult.branchSuccess(someResultClass);
} catch(Exception e) {
    // ...
}

Known problems

Conflict with option hasResultClass

Problem

If a task has both the options “isBranchingTask” and “hasResultClass”, it is not possible to use the IStateDef variant of the “branchSuccess” method. A result class object is required for the task.

Solution

  • Remove the option “isBranchingTask”.
  • Add a custom modify to set the custom end state of the task.
  • Return a branchSucces method with the result class object.

Example

try {
    // ...

    ExampleDetails exampleDetails = new ExampleDetails();
    exampleDetails.setStatus("someState");

    exampleAgent.modify(exampleDetails);

    // If no return value is needed.
    return TaskResult.branchSuccess((SomeResultClass) null);
    // If a retrun value is needed.
    return TaskResult.branchSuccess(someResultClassObject);
} catch(Exception e) {
    // ...
}

References