Switch Rules
Switch Rules are a subset of rules you can define once but use multiple times throughout your Ruleset (Version 2 only). They operate similarly to switches in Java by giving you the ability to filter a generic list of objects. Unlike Java, a Switch will exit automatically as soon as a case is matched. Switch rules must contain Type Guards, Case Conditions, or both.
Cases, Type Guards, and Case Conditions
When using Switch Rules, you will need to understand how Cases, Case Conditions, and Type Guards are used and selected in the Ruleset editor.
Case
- Cases can only call Methods;
- A matched Case automatically "breaks" (unlike Java) which means that no more matching is attempted.
Type Guards
When looping over a generic list of Objects, a Type Guard is used to match on a specific Type. Type Guarding allows you to narrow down an object type within a conditional block.
Switch Rules using Type Guards support integration with Salesforce, NetSuite, and other cloud applications, due to their type hierarchy. As such, these are currently supported with the Object Schema only. Two examples of Type Guards are highlighted here.
To remove a Type Guard from a Case, you must add a Case Condition.
Clarify prevents you from deleting a Type Guard unless a Case Condition exists (and vice-versa).
Switch Rules with Type Guards and Case Conditions (for Object Schemas only)
There may be a scenario when a Source Schema has an Object containing a flag that will determine what it gets mapped to target-side. Since it is the same type of Object, a Type Guard is not enough to match. You must use a condition over the Object's flag to improve the condition.
Switch Rules with Case Conditions and no Type Guard (for non-Object Schemas)
If using Switch Rules with a Schema other than the Object Schema, then only Case Conditions are supported. When a switch case provides a Case Condition in place of a Type Guard, the only difference between other rule types containing a condition is that the case will match once and break. Any cases below the matched case will not be evaluated.
Switch Rules that do not use Type Guards can still be used to filter a generic list.
- Select a Case;
- Right-click and select Add Case Condition.
Default Case
In some situations, you may want to perform an operation even if no Cases are matched; to do this, the Switch Rule provides a Default Case, which is only called when there is no other match in the Rule.
A Switch Rule may contain a Default Case, which will appear as the last Case in a Switch Rule. The Default Case can be used to perform a task when no other Case in the Switch Rule is matched. A Default Case does not contain any Type Guards or Conditions. Here is an example:
- Select the Switch Rule or case within the Switch Rule;
- Right-click and select Add Default Case.