Running actions

Action formulas run when formula buttons are pressed. Unlike regular formulas that calculate values, action formulas make things happen. They enable complex workflows and business logic that go far beyond simple calculations.

What action formulas can do

Action formulas can handle sophisticated interactions like:

Action functions and syntax

Action formulas use 30 specialized action functions that do everything regular buttons can do and more. They also support the := assignment operator for setting property values. Both are exclusive to action formulas.

Here’s a simple example that asks for the user’s name and greets them:

AWAIT(PROMPT("What's your name?"), BANNER("Hi " & Result & "!"))AWAIT(PROMPT("What's your name?"); BANNER("Hi " & Result & "!"))

Action formulas can perform multiple actions, either one after another or by waiting for one to complete before starting the next. They support conditional logic, allowing different actions based on varying conditions. This flexibility makes it possible to model complex business logic.

Action formulas attach only to the OnPress property of formula buttons.

Conditional logic with IF

Use functions like IF or SWITCH to perform different actions based on conditions.

This formula sends an email if all fields are valid and shows an alert message otherwise:

IF(AND(App.Fields.Valid), EMAILREPORT({ App }, "test@example.com"), ALERT("Please correct the fields first."))IF(AND(App,Fields,Valid); EMAILREPORT({ App }; "test@example.com"); ALERT("Please correct the fields first."))

App.Fields.ValidApp,Fields,Valid returns a logical array where TRUE indicates a valid field and FALSE indicates an invalid field. AND returns TRUE only when all elements are TRUE, meaning all fields are valid.

Running multiple actions

Action formulas can perform any number of actions. Separate actions with ;;;.

This formula assigns values to two fields and hides a text box:

Field1 := SUM(FormGroup1); Field2 := Field1 * 10; TextBox1.Visible := FALSEField1 := SUM(FormGroup1);; Field2 := Field1 * 10;; TextBox1,Visible := FALSE

By chaining actions with ;;;, you can create buttons that only calculate values when pressed. For some apps, this offers an appealing alternative to automatic calculation as users type.

This formula resets all fields and returns users to the first screen:

RESET(App); GOBACK(FirstScreen)RESET(App);; GOBACK(FirstScreen)

This formula assigns values to fields on SecondScreen before navigating there:

SecondScreen!Result1 := FirstScreen!Field1 * 2; SecondScreen!Result2 := FirstScreen!Field2 * FirstScreen!Field1; GOFORWARD(SecondScreen)SecondScreen!Result1 := FirstScreen!Field1 * 2;; SecondScreen!Result2 := FirstScreen!Field2 * FirstScreen!Field1;; GOFORWARD(SecondScreen)

To restrict access to the second screen through the button only (not the Next button), set the NextScreenAvailable property of the preceding screen to FALSE.

Waiting for actions to complete

Many action functions take time to complete. EMAILREPORT, for example, sends reports by asking our server to create and send them, which takes a few seconds.

By default, EMAILREPORT starts the process and immediately continues to the next action. This formula starts sending a report and immediately shows a banner:

EMAILREPORT({ App }, "test@example.com"); BANNER("Sending the report, hold tight!")EMAILREPORT({ App }; "test@example.com");; BANNER("Sending the report, hold tight!")

To perform an action after the report sends successfully, use the AWAIT function. This formula shows a completion banner once the report is sent:

AWAIT(EMAILREPORT({ App }, "test@example.com"), BANNER("All done!")); BANNER("Sending the report, hold tight!")AWAIT(EMAILREPORT({ App }; "test@example.com"); BANNER("All done!"));; BANNER("Sending the report, hold tight!")

Handling errors

The AWAIT function accepts three parameters: the action, a success handler and a failure handler. Only one of the latter two is required, so you can handle either success or failure exclusively.

This formula shows an error message if sending a report fails:

AWAIT(EMAILREPORT({ App }, "test@example.com"), OnFailure: ALERT("Could not send report: " & Error.Message))AWAIT(EMAILREPORT({ App }; "test@example.com"); OnFailure: ALERT("Could not send report: " & Error,Message))

The OnFailure parameter is named, allowing us to omit the success handler. Alternatively, use BLANK()BLANK() for the success parameter:

AWAIT(EMAILREPORT({ App }, "test@example.com"), BLANK(), ALERT("Could not send report: " & Error.Message))AWAIT(EMAILREPORT({ App }; "test@example.com"); BLANK(); ALERT("Could not send report: " & Error,Message))

The failure handler has access to a special Error value containing detailed error information, including a user-friendly message.

When action functions fail without an OnFailure handler, your app shows a default error message. To suppress all error messages (including your own), pass BLANK()BLANK() as the OnFailure parameter.

Next, learn about private apps that require users to sign in »