Tip: Ask users questions with action formulas

Use action formulas to ask users a series of questions. The answers are then fed into action functions that act on the information given.

Action formulas can be used for a variety of things, including sending messages if a field is valid and displaying an alert box if it isn’t, as well as performing calculations only when a button is pressed.

This tip focuses on asking users questions, using message boxes. What makes this possible are the new action functions PROMPT and PROMPT.NUMBER.

Both action functions are used to ask users for information. PROMPT reads text strings, whereas PROMPT.NUMBER only reads numbers. AWAIT is used to read the entered values.

This formula asks the user to enter the email address where a report should be sent, before sending the report:

AWAIT(PROMPT("Enter email address:"), EMAILREPORT({ App }, Result))AWAIT(PROMPT("Enter email address:"); EMAILREPORT({ App }; Result))

The second parameter to AWAIT has access to a special value named Result, containing the result communicated by the action. For PROMPT the result is the text string entered by the user. For PROMPT.NUMBER, the result is the number entered by the user.

(This is similar to the third parameter to AWAIT, which has access to a special value named Error, with additional information on what went wrong.)

If you like, you can use -> to rename the Result value:

AWAIT(PROMPT("Enter email address:"), EmailAddress -> EMAILREPORT({ App }, EmailAddress))AWAIT(PROMPT("Enter email address:"); EmailAddress -> EMAILREPORT({ App }; EmailAddress))

You can ask the user any number of questions:

AWAIT(PROMPT("First value:"), Value1 -> AWAIT(PROMPT("Second value:"), Value2 -> ALERT("First value: " & Value1 & ", second value: " & Value2 & ".")))AWAIT(PROMPT("First value:"); Value1 -> AWAIT(PROMPT("Second value:"); Value2 -> ALERT("First value: " & Value1 & ", second value: " & Value2 & ".")))

When asking multiple questions with PROMPT, it is necessary to rename the Result value. If we don’t, there is no way to access results other than the last one.

Finally, use CONFIRM to ask users to confirm a choice. This formula asks the user to confirm before resetting all fields of the app, immediately followed by displaying the first screen:

AWAIT(CONFIRM("Start over?"), RESET(App); GOBACK(FirstScreen))AWAIT(CONFIRM("Start over?"); RESET(App);; GOBACK(FirstScreen))
« Tip: Perform calculations when a button is pressed Feature: More ways to access our documentation »