Performing multiple actions in a formula

Completed

Combining functions

As you begin building your app, when possible, combine multiple functions and elements in a single formula. Creating dynamic formulas is more efficient and effective, not only for the app developer but also for the user experience. More single function formulas might mean more work to maintain, track, and update each formula. By creating multi-function formulas, updating and maintaining formulas is simpler. Also, depending on the size of your app and the number of single-function formulas, you might encounter performance problems. If possible, it's more efficient to create multi-function formulas. The following example combines multiple functions into a single formula.

Screenshot of combining functions in formulas.

The two Text Input controls have no formulas or modifications. The Text property of the selected Label control is a multi-function formula that evaluates to either "Pass" or "Fail":

If(Sum(Value(TextInput1.Text),Value(TextInput2.Text)) > 50, "Pass", "Fail")

The output of this formula appears in the label. The function also converts the text stored in the text input controls into values using the Value function. Then it adds those values together using the Sum function. In this example, 25 + 30 = 55. The If function evaluates the sum of the values to see if it's greater than 50. In this example, it evaluates to true (55 is greater than 50), so the text "Pass" shows in the Label. If the sum had been less than 50, we would have seen "Fail".

Similarly, when implementing controls, the same combined formula logic should apply. There's nothing to stop you from creating a button for every action that you would like the user to take, but it's far more efficient and effective to combine them when you can. To combine more than one action in a formula, use the semicolon (;).

Continuing with the previous example, we could add a Set function to set a global variable to the OnSelect formula of a button. This formula enables us to record the value of Label1 (either "Pass" or "Fail") and then Navigate over to Screen2 in our app. Two functions in one action.

Set(varOutcome, Label1.Text); Navigate(Screen2,ScreenTransition.Cover)

Note

The actions are performed in the order in which they appear in the formula. The next function won't start until the previous function has completed. If an error occurs, subsequent functions will not process.