Examples of scripts for conditions on gateway transitions

Example 1

This example shows how to use a script to make a process follow a certain path depending on the value a user selects in a drop-down list.

Create a context variable Premises of the Drop-Down List type, with values Residential and Nonresidential.

Create a task with this context variable.

On one of the transitions of an exclusive OR-gateway, add a script on the Transition Condition tab.

A C# method from the Scripts tab of the process is the script for the gateway. The method must return a boolean value (true or false).

The script uses a service variable for the gateway transition gatewayVar, and the context variable Premises. It is checked for the Residential value.

public bool Transition1(Context context, object GatewayVar)
{
      if (context.Premises.ToString()=="Residential")
      { 
          return true; 
      } 
      else
      { 
          return false; 
      }    
}
 

If the condition is true, the process goes to the residential premises department, if false - to the nonresidential premises department, since there are two values in the list and the field is required.

Example 2

Consider another example. In the condition of an exclusive OR-gateway, the value of the Order Amount context variable is analyzed. If its value is more than 1000000, the process goes to the legal advisor.

Create an Order Amount context variable. Its value will be specified by a sales rep in the task "Fill in contract data". Next, on one of the transitions of the gateway add a script that will check the value of the context variable.

public bool transition2(Context context, object GatewayVar)
{
    if (context.OrderAmount > 1000000)
        {
           return true;                
        }
    else
        {
          return false;
        }
}