Conditions: General Information

A condition is a Boolean statement that is checked in a workflow. When the statement is true, a workflow component can change to your specifications.

Learning Objectives

In this chapter, you will learn where and how a condition can be applied.

Applicable Scenarios

You can use a condition in the following ways:

  • To change Boolean properties of each action, such as its visibility and availability
  • To change Boolean properties of each field, such as its visibility, requirement, and availability
  • To check whether a transition should be performed

Declaring of a Condition

You declare a condition in a condition pack, which is a class that inherits from the Condition.Pack class. In that class, you define a member of the Condition type by calling the GetOrCreate method. As a parameter, you provide a fluent BQL statement that uses the FromBql or FromBqlType method. An example of a condition definition is shown in the following code.

public class Conditions : Condition.Pack
{
  public Condition IsOnHold => 
    GetOrCreate(b => b.FromBql<hold.IsEqual<True>>());
  public Condition IsCompleted => 
    GetOrCreate(b => b.FromBql<completed.IsEqual<True>>());
  public Condition IsOnCreditHold => 
    GetOrCreate(b => b.FromBql<creditHold.IsEqual<True>>());
}

The Condition.Pack class provides the GetOrCreate method, which registers a condition definition under the name of the class property. Later, you can retrieve the condition through this property by using the GetPack method.

You can combine conditions by using AND, OR, and NOT C# operators to dynamically create and register new conditions.

Important: A condition that is declared using the Condition.Pack class is automatically registered in the screen configuration and does not need to be added to it manually.

Uses of Conditions

You can use conditions in the following ways:

  • To disable an action depending on a condition: In this case, you should call the IsDisabledWhen method while adding an action to a screen configuration and provide a condition as a parameter. For an example, see Step 2 of the Workflow Actions: To Configure the Conditional Appearance of the Action activity.
  • To hide a field, disable the field, or make the field required depending on a condition. You do this while configuring the state of the field in the screen configuration. For details, see Configuration of a Field State.
  • To hide a dialog box field depending on a condition: In this case, you call the IsHiddenWhen method while adding this field to a dialog box and provide a condition as a parameter. For details, see Configuration of the Fields of a Dialog Box.
  • To check whether a transition should be performed: To do this, you call the When method while adding the transition in a transition group and provide a condition as a parameter. This way, you can also create multiple transitions with a single initial state if these transitions should be triggered by the same action or event. The transition is performed when the provided condition is true. An example is shown in the following code.
    .WithTransitions(transitions =>
    {
      transitions.AddGroupFrom(initialState, ts =>
      {
        ...
        ts.Add(t => t 
          .To<State.balanced>()
          .IsTriggeredOn(g => g.initializeState)
          .When(conditions.IsBalanced)
      }
    }

    For a full example, see Step 3 of the Transitions: To Implement a Group of Transitions activity.