About this article
Switch() is a function that compares one value to multiple values and returns results accordingly. If nothing matches it simply returns the DefaultValue. Similar to a nested IfElse() function where a IfElse() function is nested in the Else portion of the function.
Pre-requisites
|
Syntax
Syntax | {{Switch(ValueToCompare,Value1,Result1, Value2, Result2..., DefaultValue)}} |
Input | ValueToCompare, Value1, Value2..., DefaultValue |
Output | Value1 -> Result1, Value2 -> Result2, Else -> DefaultValue |
Example 1
Using a dropdown for marking the sensitivity of a document with a text binding.
Binding | {{Switch(Form.Sensitivity.Name,"Top Secret","Strictly Confidential","Internal","Internal Only","Public")}} | ||
Input | Form.Sensitivity = "Top Secret" | Form.Sensitivity = "Internal" | Form.Sensitivity = Not "Internal" or "Top Secret" |
Output | "Strictly Confidential" | "Internal Only" | "Public" |
Example 2
Using a User Profile company field to translate from numerical value to company name for use in a document property. The below binding being inserted into the binding field of the document property.
Binding | {{Switch(UserProfile.Company,"1","Templafy ApS","2","iWriter","No Company")}} | ||
Input | UserProfile.Company = "1" | Form.Sensitivity = "2" | Form.Sensitivity = Not "1" or "2" |
Output | "Templafy ApS" | "iWriter" | "No Company" |
Example 3
Instead of plain text you can also use other form fields in the binding, e.g. Form.Subject.
The value of Form.Subject is "Meeting".
Binding | {{Switch(Form.Choice,"1", "Hello world", "2", Form.Subject, "No Choice")}} | ||
Input | Form.Choice = "1" | Form.Choice = "2" | Form.Choice = Not "1" or "2" |
Output | "Hello world" | "Meeting" | "No Choice" |
Example 4
Using the Switch function in combination with StringJoin() to show specific text depending if both questions 1 and 2 are empty.
Binding | {{Switch(StringJoin("", Form.Question1, Form.Question2),"", "Question 1 and 2 are empty", "Question 1 and/or 2 contain(s) a value")}} | |
Input | Form.Question1 = "", Form.Question2 = "" | Form.Question1 = "", Form.Question2 = "Hello world" |
Output | "Question 1 and 2 are empty" | "Question 1 and/or 2 contain(s) a value" |
Example 5
In this example this Offices data source is used:
Depending on the DocumentLanguage set in the user profile the phone number is shown in a different format. If the DocumentLanguage is not "nl-NL" or not set then the default value is returned.
Binding | {{Switch(DocumentLanguage,"nl-NL", UserProfile.Office.Phone_NL, UserProfile.Office.Phone_EN)}} | ||
Input | DocumentLanguage = "nl-NL" | DocumentLanguage = "en-US" | DocumentLanguage = not set |
Output | "040 - 1234 567" | "+31 (0)40 1234 567" | "+31 (0)40 1234 567" |
Comments
0 comments
Article is closed for comments.