Skip to content

Home

Development

IDEs

JAR services

API Explorer

Making decisions in Event Based Workflow

So far, we've only been creating workflows that have two states and don't diverge in any way. Event Based Workflow has the capability to decide which transition to take based on events. For this example, we'll be making a workflow of a payment system. A starting state simulates a checkout from a client. Another two states are for handling the chosen payment method. One is for retrieving card details while the other is for displaying bank information. How do we invoke a state based on a client's payment method? To do this, we create a transition for each payment method. We'll use a Event Based Workflow input called payment that defines the chosen payment method and map it to $fluxEvent.

  1. Create a transition from the Checkout state to the Get Card Details state. When prompted for the event, type in card.
  2. Create another transition from the Checkout state to the Display Bank Information state. When prompted for the event, type in bank. Notice that checkout state shows a validation error. This is because we have defined the events of the transitions and $fluxEvent is not set. We'll fix that next.
  3. Select the Checkout state and go to the Mapper. Map payment from the Event Based Workflow input to the $fluxEvent variable. At this point, the validation error should be gone.
  4. Provide an action for retrieving card details and displaying bank information state. For this example, we'll just log the process.

Creating a multi-transition Event Based Workflow

Creating a multi-transition Event Based Workflow

To test, run the Event Based Workflow and set the value of payment to card. Notice that the card details state's action is invoked. Rerun the Event Based Workflow and this time set the value of payment to bank. This time, the bank detail state's action is invoked instead.

Running multi-transition Event Based Workflow states

Running multi-transition Event Based Workflow states

And just like that, you've told Event Based Workflow how to make a decision. $fluxEvent is the variable that Event Based Workflow checks and compares against all available transitions to decide how to proceed. All outcomes should be accounted for. This allows you to assign a transition that catches all other events.

Quickly navigate to states or transitions with validation issues

Use the shortcuts and to navigate to the next or previous Event Based Workflow state or transition with a validation issue.

Navigating to Event Based Workflow states or transitions with issues