CONFIRM function

CONFIRM(Body, Title?, CancelLabel?, OkLabel?) CONFIRM(Body; Title?; CancelLabel?; OkLabel?)

Body

Text

The body of the window.

Title

Text (optional)

The title of the window. If omitted, no title is used.

CancelLabel

Text (optional)

The label of the cancel button. If omitted, a default label is used, whose exact wording depends on the language the app has been configured to use. "Cancel" is used for apps in English.

OkLabel

Text (optional)

The label of the OK button. If omitted, a default label is used, whose exact wording depends on the language the app has been configured to use. "OK" is used for apps in English.

Returns

Promise

A promise, which succeeds if the OK button is pressed and fails if the cancel button is pressed. Pass this promise as the first parameter to AWAIT (and related functions) to take action after the promise has succeeded or failed.

Asks the user to confirm. AWAIT(CONFIRM("Reset all fields?"), RESET(App))AWAIT(CONFIRM("Reset all fields?"); RESET(App)) resets all fields of the app, but only after the user has confirmed that the action should be carried out.

This function can only be used from an action formula. It is typically invoked from a formula associated with the OnPress property of a formula button.

The shown window has a cancel button and an OK button. The labels may be set using the CancelLabel and OkLabel parameters, respectively. If a label is omitted, a label appropriate for the language of the app is used. The Title parameter may be used to set the title.

To display an alert with only an OK button, use ALERT instead. To display a banner which disappears automatically, use BANNER. Use PROMPT or PROMPT.NUMBER to ask the user to enter information.

Taking action when the user presses OK

CONFIRM returns a promise, which succeeds when the OK button is pressed and fails when the cancel button is pressed. Use AWAIT to take action when a button is pressed.

The first parameter to AWAIT should be the promise returned from CONFIRM and the second parameter should be a formula fragment that is run when the user presses the OK button. If you want to run a formula fragment when the cancel button is pressed, use the third parameter to AWAIT.

This formula sends a report, after receiving confirmation from the user:

AWAIT(CONFIRM("Send report?", Title: "Question", OkLabel: "Send"), EMAILREPORT({ App }, "test@example.com"))AWAIT(CONFIRM("Send report?"; Title: "Question"; OkLabel: "Send"); EMAILREPORT({ App }; "test@example.com"))

It is a good idea to set the label of the OK button to a verb, in this case Send, to make it clear to the user what action is initiated when the button is pressed.

Combining CONFIRM with PROMPT

With AWAIT, multiple actions can be combined. This formula first asks the user if they want to send a report. If the user consents, they are asked to enter an email address. Finally, the report is sent to the entered email address:

AWAIT(CONFIRM("Send report?", Title: "Question", OkLabel: "Send"), AWAIT(PROMPT("Enter recipient:"), EMAILREPORT({ App }, Result)))AWAIT(CONFIRM("Send report?"; Title: "Question"; OkLabel: "Send"); AWAIT(PROMPT("Enter recipient:"); EMAILREPORT({ App }; Result)))

Examples

AWAIT(CONFIRM("Reset all fields?"), RESET(App))AWAIT(CONFIRM("Reset all fields?"); RESET(App))

Resets all fields of the app, but only after the user has given confirmation.

AWAIT(CONFIRM("Send report?", Title: "Question", OkLabel: "Send"), EMAILREPORT({ App }, "test@example.com"))AWAIT(CONFIRM("Send report?"; Title: "Question"; OkLabel: "Send"); EMAILREPORT({ App }; "test@example.com"))

Sends a report, after receiving confirmation from the user.

AWAIT(CONFIRM("Send report?", Title: "Question", OkLabel: "Send"), AWAIT(PROMPT("Enter recipient:"), EMAILREPORT({ App }, Result)))AWAIT(CONFIRM("Send report?"; Title: "Question"; OkLabel: "Send"); AWAIT(PROMPT("Enter recipient:"); EMAILREPORT({ App }; Result)))

Asks the user if they want to send a report. If so, the email address of the recipient is collected before sending the report to said email address.

AWAIT(CONFIRM("Send a report or post to Slack?", CancelLabel: "Report", OkLabel: "Slack"), RELAY({ App }, "https://hooks.example.com/123"), EMAILREPORT({ App }, "test@example.com"))AWAIT(CONFIRM("Send a report or post to Slack?"; CancelLabel: "Report"; OkLabel: "Slack"); RELAY({ App }; "https://hooks.example.com/123"); EMAILREPORT({ App }; "test@example.com"))

Asks the user if they want to send a report or post to a Slack channel. The cancel button is labeled Report and the OK button is labeled Slack. EMAILREPORT is used to send the report if the cancel button is pressed, and RELAY is used to communicate with Slack through a third-party service if the OK button is pressed.