Axivox User guide
Back to the site

Switch / Case

Routes the call based on the value of a variable. Each declared case creates its own output, by exact match or by pattern, and Default catches the rest.

In brief

Outputsone per declared case, plus Default
Output labelthe case's value, preceded by ~ when Regex is checked
FieldsExpression to test, then a Case value array with a Regex checkbox
Default comparisonexact match, uppercase and spaces included
Number of casesunlimited
Orderthe first matching case wins; the following ones are not evaluated

The help text shown in the window is: "Each case creates an output; 'Default' is taken if no case matches. Check 'Regex' to treat the value as a regular expression (e.g. ^\+251, ^0[1-9][0-9]{7}$). Otherwise, exact match."

How it works

The module first computes the expression to test, generally a variable written {{my_variable}}. It thus gets a piece of text, the one the variable carries at the time the call passes through.

It then goes through your cases from top to bottom and stops at the first one that matches. If none match, it takes Default.

Exact match

Without the Regex checkbox, a case matches when the value is strictly identical: Premium and premium are two different values, and one extra space is enough to make the comparison fail.

Pattern, or regular expression

A regular expression is a description of a shape rather than a value. Instead of listing the thousands of numbers that start with 02, you describe "starts with 02, then digits."

A handful of symbols cover almost every need:

NotationWhat it means
^the start of the value
$the end of the value
\da digit
[0-9]a digit, another way of writing it
[1-9]a digit from 1 to 9
+the preceding symbol, one or more times
*the preceding symbol, zero or more times
{7}the preceding symbol, exactly seven times

The two examples in the interface read as follows: ^\+251 matches any value that starts with +251, and ^0[1-9][0-9]{7}$ matches a nine-digit value that starts with a zero followed by a digit from 1 to 9.

Write the pattern alone, without wrapping it in slashes. ^02 is correct, /^02/ will match nothing.

What to fill in

FieldWhat is expectedIf you leave it empty
Expression to testa variable, for example {{language}}, or text that contains onethe tested value is blank, and only a blank case or Default can be taken
Case valuethe expected value, or the pattern if Regex is checkedwithout Regex, the case only matches a value that is itself blank; with Regex, it matches everything and catches every call
Regexchecked, the value becomes a patternexact match comparison

The Add button creates a case row, Delete removes the one on that row. Save closes the window, and the module's outputs are relabeled immediately.

Steps

  1. Place the Switch / Case module and connect the previous node to its input.
  2. Open it and fill in the Expression to test, copying the variable from the Available variables panel rather than retyping it.
  3. Click Add and enter the Case value. Repeat for each value you want to distinguish.
  4. Check Regex only on rows where you are describing a shape, not a specific value.
  5. Arrange your cases from the most specific to the most general: the first one that matches wins.
  6. Click Save. The module now shows one output per case, plus Default.
  7. Connect each output to its destination, Default included: a chosen output that leads nowhere hangs up the call.
  8. Place a Debugging module right before, with the tested variable as its message. You'll read the value actually being compared.
  9. Click Save, then Apply changes in the top banner.
  10. Call your number while triggering each of the cases, and check that the call goes where you expect.

If it doesn't work

All calls end up in Default. First read the value actually being tested, with a Debugging module placed right before. Nine times out of ten it is blank, because the module that sets the variable was not passed through, or because the name written between braces doesn't match.

My value is correct but the case is not taken. The comparison is exact: Premium is not premium, and a trailing space counts. Check Regex and describe the shape, for example ^[Pp]remium$.

My pattern never matches. Write it without slashes around it: ^02\d+ and not /^02\d+/. Then check that a malformed pattern isn't going unnoticed: it never matches and shows no error.

The same case always wins, even though two could match. This is the expected behavior. Move the more specific case above the more general one, or narrow the pattern of the more general one.

The call cuts off even though a case does match. That case's output is not connected to anything. Check every output of the module, Default included, after adding or removing a case: the outputs are renumbered.

How the call flow is built, explained in pictures

See the Dial plans page