Workflow API: Support of Action Sequences

This topic describes support of action sequences by Workflow API.

Defining an Action Sequence

To define an action sequence, a developer should do the following:

  1. At the screen configuration level, call the WithActionSequences method.
  2. In the lambda expression for the WithActionSequences method, call the Add method to add a new sequence.
    Note: A developer can also call the Replace method to replace an existing sequence or the Remove method to remove an existing sequence. To avoid errors, there is no option to update an existing sequence.
  3. In the lambda expression for the Add method, configure the sequence by using the following methods:
    • AfterAction: Required. Specifies the triggering action (the action after which the sequence should be executed). A developer can specify either an action from the graph or an action defined by using Workflow API.
    • RunAction: Required. Specifies the action that should be executed in the sequence.

      Only one action can be added to a sequence. To add a sequence of multiple actions, a developer needs to add multiple sequences. For example, to add the A > B > C sequence of actions, a developer needs to add the A > B sequence and the B > C sequence.

    • StopOnError: Optional. Specifies whether the system should stop the execution of subscribers if the triggering action fails. By default, the sequence is stopped if an error occurs.
    • AppliesWhen: Optional. Specifies the condition depending on which the sequence should be executed.

      A developer can also call the AppliesAlways method to always execute the sequence.

    • WithFieldAssignments: Optional. Assigns the fields of a dialog box that is configured for the second action of the sequence (specified in the RunAction method). The assignment is performed after the first action (specified in the AfterAction method) is executed.
      Note: If a dialog box is configured for an action specified in the RunAction method (the second action in the sequence), this dialog box is not displayed during the execution of the sequence. So the only way to provide values that are different from default ones in the dialog box is to specify them in the WithFieldAssignments method.

The following code shows an example of defining a sequence of actions ActionA > ActionB.

var context = configuration.GetScreenConfigurationContext<SOOrderEntry, 
                                                          SOOrder>();
  context.UpdateScreenConfigurationFor(config => config
    .WithActions(actions => ...)
    .WithFlows(flows => ...)
    .WithActionSequences(sequences =>
    {
      sequences.Add(s => s
        .AfterAction<SOOrderExtension>(g => g.ActionA)
        .RunAction<SOOrderExtension>(g => g.ActionB)
        .StopOnError(true)
        .AppliesWhen(condition)
        .WithFieldAssignments(fields =>
        {
          fields.Add("FormFieldA", f => f.SetFromValue("Value"));
          fields.Add("FormFieldB", f => f.SetFromExpression("=EXPRESSION"));
        }));
    }));

Order of Execution

The system executes action sequences in the order they are defined in the code. For example, if the code contains the action sequences A > B, B > C, and A > D with no conditions, the system will first execute the sequence A > B, then the sequence B > C, and then the sequence A > D, so the order of actions will be A > B > C > D. If the sequence A > B has a condition and it is not met, the system will proceed to the sequence A > D.