Skip to main content
?

switch

Summary

This Action returns values that fits on switch case.
If the input value is not in the case list, it returns the value of default.

Description

The SWITCH ACTION evaluates an expression, matching the expression's value against a series of CASE clauses, and executes statements after the first CASE clause with a matching value, until DEFAULT statement is encountered. DEFAULT clause of a switch statement will be jumped to if no CASE matches the expression's value.

Fields

In SWITCH Action there are 5 type fields.

  • SWITCH : Criteria for SWITCH
  • CASE : Target's CASE
  • Return : Return result IF the Creteris is 'CASE'
  • Add CASE : Add more CASE
  • Default Return : Default return result
Version Location

- SWITCH

This field is Criteria for SWITCH. You can change the type to 'Values (string, number...)', 'References Data', 'Action' ...' like below.

Version Location
tip

But, I suggest use 'Reference Data' or 'Action'. type.
Because we need value that changes through the case.

- CASE

This field is Target's CASE.
Usually, use String Type, but you can use another types,
For examples, Object, Referece Data, Action...

Version Location
tip

But, I suggest use kind of Fixed Value.
Such as 'string' or 'number'. type.
Because Case requires a fixed value.

- Return

This field is 'Return' result If the SWITCH is same with CASE.
You can change Return Type to Object, Referece Data, Action...

Version Location

- Add CASE

If you want to make more CASE,
Click Add CASE button.
Then you can make more CASE whatever you want!

Version Location

- Default Return

This field is Default Return
If the SWITCH is not fits any CASE,
You will get 'Default Return' from this field.

Version Location

Example

Let's Use SWITCH ACTION!

Target - String Example

Let's imagine.
I want to make an if statement true only when data with reference data is data that meets the criteria I set.

goal

We will put the string 'Autoflow' in the ref_data,
If the value is the same as CASE criterion, the value will be returned as 'ref is autoflow!'. If not, I would return Default Return value.

We will get Action result like below.

  • If ref_data is the same as CASE,
    • it would return 'ref is Autoflow!'
  • If ref_data is not the same as CASE,
    • it would return 'ref is not in CASE!'

1. Prepare Reference Data

We will make Reference Data by 'Variable/set Action'

I just add value as String, then I put 'Autoflow' in value.
Then I changed OUTPUT's name to 'ref_data'

Version Location

2. Set up SWITCH Action.

2.1. Set up SWITCH field.

Click 'null' to change 'data' type.

Version Location

Click 'data' type.

Version Location

Change Scope and Path as variable > ref_data

Version Location
2.2. Set up CASE field.

Click 'null' to change 'string' type.

Version Location

Click 'string' type.

Version Location

Write Autoflow in CASE field's value.

Version Location
2.3. Set up Return field.

Click 'null' to change 'string' type.

Version Location

Select 'string' type.

Version Location

Write 'ref is Autoflow' in Return field's value.

Version Location
2.4. Set up Default Return field.
Version Location

Select 'string' type.

Version Location

Write 'ref is not in CASE' in in Default Return field's value.

Version Location
We are ready to use SWITCH Action! 👏

3. Get a result by using Simulation!

Start Simulation, then See the result! 👀

tip

You don't know how to use Simulation in Autoflow?
Then, Click here! 🔗

Version Location
3.1 Revive simulation to the corresponding value of the case.

I put CASE string to Autoflow and ref_data is Autoflow. That means I will get one of SWICH CASE result from SWITCH Action.

Now we can see Result! in Action output.👀
ACTION OUPUT is 'ref is Autoflow!' which we wanted to get.

Version Location
3.2 Revive simulation to values that do not correspond to the case.

This time, let's change the ref-data value to 'eric'.
This means that it does not correspond to SWITCH CASE.
We can imagine that the result will be a Default Return value.

Version Location

Now we can see Result! in Action output.👀
ACTION OUPUT is 'ref is not in CASE!' which we imagined.

Version Location