Docs Menu
User Guide / Control Structures / Switch

Switch Step

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case. Syncloop has inherited a similar execution of a switch statement which is present in OO programming languages.

Switch Step is only supported in an API service. It will execute the cases & matched case will be executed. The switch case cannot execute alone without case steps at least one case is required to perform the switch.

A switch statement can be used anywhere in a API service and a nested switch statement is also supported.

Users can add a SWITCH step by right click context menu in the steps area which is shown in the image below.

switch statement

Switch Properties

1. Status: To enable/disable the switch case. The default switch will be in enabled mode. If the status is selected as disabled in the case switch & its child cases and further steps will not execute when the API service will be invoked either from HTTP or from another service.

2. Snapshots: Create a runtime data state snapshot for the switch step.

3. Comment: Add a comment on the switch step.

4. Switch: The user can put the following types of data to execute cases.

  • Constants: Can use different types of single (Not an Array) constant values such as String, integer, Date, Number, and Boolean but Document, Byte, and Object are not accepted.
  • Variable: Can use a variable of types such as String, integer, Date, Number, Boolean Only (Not an Array). The variable should be present only in the pipeline. The variable can be not resolved from LOCAL, PACKAGE, or GLOBAL properties.

Case

A switch step can only have cases as the child and it doesn’t support other steps such as Transformer, Invoke, etc. as an immediate child but inside the case, other steps can be added. The execution of the case is also inherited and the case can be added by right click on Switch Step as shown in the image.

Case

Case Properties

1. Status: To enable/disable the case. The default case will be in enabled mode. If the status is selected as disabled in that case the CASE & its child steps will not execute when the API service will be invoked either from HTTP or from another service.

2. Snapshots: Create a runtime data state snapshot for the case step.

3. Comment: Add a comment on the case step.

4. Case: The user can put the following data/keywords to execute.

  • Constants: Can use different types of single (Not an Array) constant values such as String, integer, Date, Number, and Boolean but Document, Byte, and Object are not accepted.
  • #default: This is similar to the default statements in other programming languages. When none of the cases will be matched in that case it will execute.
  • #null: Syncloop offers one more keyword along with the default. In case the variable will be null, not assigned in the pipeline, or doesn’t exist, in that case, #null will execute. This #null case is not mandatory and API service will never be broken in case of null data.