Skip to content
bdahneke edited this page Aug 29, 2018 · 5 revisions

This switch statement allows the contents of a variable to be tested for a match against a list of values. Each value is called a case and the variable being switched on is checked for each case. If defined, the DefaultCase is executed if no match is found.

Parameters

Parameter Name Description Required
MatchValue A string or variable whose contents is used in the cases evaluation for match Yes
Cases An array of CaseBlocks. Yes
DefaultCase The case block that contains the commands to be executed if there is no match No

The case blocks are evaluated in order and the first one whose CaseValue matches the MatchValue is executed as the match. A CaseBlock contains a CaseValue and an associated DoBlock that contains the commands to be executed. The CaseValue must evaluate to a string or a regular expression.

Example:

{
  "Switch": {
    "MatchValue": "%ReturnStatus%",
    "Cases": [
      {
        "CaseValue": "(CHECKSYS=[1-9]+.*)|(Permission denied)",
        "Do": [
          {
            "Throw": { "Value": "Insufficent rights" }
          }
        ]
      },
      {
        "CaseValue": "error: minimum password length is",
        "Do": [
          {
            "Throw": { "Value": "password is too short" }
          }
        ]
      },
      {
        "CaseValue": "error: maximum password length is",
        "Do": [
          {
            "Throw": { "Value": "password is too long" }
          }
        ]
      }
    ],
    "DefaultCase": {
      "Do": [
        {
          "Comment": { "Text": "Password Length is ok" }
        },
        {
          "Return": { "Value": true }
        }
      ]
    }
  }
}