Function: switch()
Evaluates a set of conditions in turn, and returns the associated result for the first match.
Syntax
switch(
[condition1, result1],
[condition2, result2],
[conditionN, resultN],
defaultResult
)
Argument | Type | Description |
---|---|---|
conditionN | Boolean | The condition to be checked. If it evaluates to true the corresponding result is returned and the switch statements ends. |
resultN | String | Result to be returned if the condition is True. |
defaultResult | String | If no previous condition has evaluated to True, this is the result to be returned. |
Examples
This example shows how attribute in.cli, holding a telephone number, can be compared to a number of start codes and resolved to a destination. If none of the codes are matched, "Elsewhere" is the default destination returned.
switch( [startsWith(in.cli, "01223"), "Cambridge"], [startsWith(in.cli, "01604"), "Northampton"], "Elsewhere" )
Returns "Cambridge" if in.cli = "01223456765".
This example shows how attribute in.city, can be used to set a region value. If none of the codes are matched, "Unknown" is the default value returned.
switch( [in.city == "Cambridge", "South"], [in.city == "Manchester", "North"], "Unknown" )
Returns "South" if in.city = "Cambridge".