|
| 1 | +--- |
| 2 | +title: App object | Microsoft Docs |
| 3 | +description: Reference information, including syntax and examples, for the App object in PowerApps |
| 4 | +author: gregli-msft |
| 5 | +manager: kvivek |
| 6 | +ms.service: powerapps |
| 7 | +ms.topic: reference |
| 8 | +ms.custom: canvas |
| 9 | +ms.reviewer: anneta |
| 10 | +ms.date: 05/29/2019 |
| 11 | +ms.author: gregli |
| 12 | +search.audienceType: |
| 13 | + - maker |
| 14 | +search.app: |
| 15 | + - PowerApps |
| 16 | +--- |
| 17 | +# App object in PowerApps |
| 18 | + |
| 19 | +Provides information about the currently running app and control over the app's behavior. |
| 20 | + |
| 21 | +## Description |
| 22 | + |
| 23 | +Like a control, the **App** object provides properties that identify which screen is showing and that prompt the user to save changes so that they're not lost. Every app has an **App** object. |
| 24 | + |
| 25 | +You can write formulas for some properties of the **App** object. At the top of the **Tree view** pane, select the **App** object as you would any other control or screen. View and edit one of the object's properties by selecting it in the drop-down list to the left of the formula bar. |
| 26 | + |
| 27 | +> [!div class="mx-imgBorder"] |
| 28 | +>  |
| 29 | +
|
| 30 | +## ActiveScreen property |
| 31 | + |
| 32 | +The **ActiveScreen** property identifies the screen that's showing. |
| 33 | + |
| 34 | +This property returns a screen object, which you can use to reference properties of the screen or compare to another screen to determine which screen is showing. You can also use the expression **App.ActiveScreen.Name** to retrieve the name of the screen that's showing. |
| 35 | + |
| 36 | +Use the **[Back](function-navigate.md)** or **[Navigate](function-navigate.md)** function to change the screen that's showing. |
| 37 | + |
| 38 | +## OnStart property |
| 39 | + |
| 40 | +The **OnStart** property runs when the user starts the app. App makers often use this property to perform these tasks: |
| 41 | + |
| 42 | +- Retrieve and cache data into collections by using the **[Collect](function-clear-collect-clearcollect.md)** function. |
| 43 | +- Set up global variables by using the **[Set](function-set.md)** function. |
| 44 | +- Navigate to an initial screen by using the **[Navigate](function-navigate.md)** function. |
| 45 | + |
| 46 | +This formula is evaluated before the first screen appears. No screen is loaded, so you can't set context variables with the **[UpdateContext](function-updatecontext.md)** function. However, you can pass context variables with the **Navigate** function. |
| 47 | + |
| 48 | +After you change the **OnStart** property, test it by hovering over the **App** object in the **Tree view** pane, selecting the ellipsis (...) that appears, and then selecting **Run OnStart**. Unlike when the app is loaded for the first time, existing collections and variables will already be set. To start with empty collections, use the **[ClearCollect](function-clear-collect-clearcollect.md)** function instead of the **Collect** function. |
| 49 | + |
| 50 | +> [!div class="mx-imgBorder"] |
| 51 | +>  |
| 52 | +
|
| 53 | +## ConfirmExit properties |
| 54 | + |
| 55 | +Nobody wants to lose unsaved changes. Use the **ConfirmExit** and **ConfirmExitMessage** properties to warn the user before they close your app. |
| 56 | + |
| 57 | +> [!NOTE] |
| 58 | +> **ConfirmExit** doesn't work in apps that are embedded in, for example, Power BI and SharePoint. |
| 59 | +
|
| 60 | +> [!NOTE] |
| 61 | +> At present, these properties can reference controls on only the first screen if the **Delayed load** preview feature is enabled (which it is by default for new apps). If references are made, PowerApps Studio doesn't show an error, but the resulting published app doesn't open in PowerApps Mobile or a browser. We're actively working to lift this limitation. In the meantime, you can turn off **Delayed load** in **File** > **App settings** > **Advanced settings** (under **Preview features**). |
| 62 | +
|
| 63 | +### ConfirmExit |
| 64 | + |
| 65 | +**ConfirmExit** is a Boolean property that, when *true*, opens a confirmation dialog box before the app is closed. By default, this property is *false*, and no dialog box appears. |
| 66 | + |
| 67 | +Use this property to show a confirmation dialog box if the user has made changes but not saved them. Use a formula that can check variables and control properties (for example, the **Unsaved** property of the [**Edit form**](../controls/control-form-detail.md) control). |
| 68 | + |
| 69 | +The confirmation dialog box appears in any situation where data could be lost, as in these examples: |
| 70 | + |
| 71 | +- Running the [**Exit**](function-exit.md) function. |
| 72 | +- If the app is running in a browser: |
| 73 | + - Closing the browser or the browser tab in which the app is running. |
| 74 | + - Selecting the browser's back button. |
| 75 | +- If the app is running in PowerApps Mobile (iOS or Android): |
| 76 | + - Running the [**Launch**](function-param.md) function.<br>The **Launch** function doesn't trigger the dialog box in a browser because another tab opens so that data isn't lost. |
| 77 | + - Swiping to switch to a different app in PowerApps Mobile. |
| 78 | + - Selecting the back button on an Android device. |
| 79 | + |
| 80 | +The exact look of the confirmation dialog box might vary across devices and versions of PowerApps. |
| 81 | + |
| 82 | +The confirmation dialog box doesn't appear in PowerApps Studio. |
| 83 | + |
| 84 | +### ConfirmExitMessage |
| 85 | + |
| 86 | +By default, the confirmation dialog box shows a generic message, such as **"You may have unsaved changes."** in the user's language. |
| 87 | + |
| 88 | +Use **ConfirmExitMessage** to provide a custom message in the confirmation dialog box. If this property is *blank*, the default value is used. Custom messages are truncated as necessary to fit within the confirmation dialog box, so keep the message to a few lines at most. |
| 89 | + |
| 90 | +In a browser, the confirmation dialog box might appear with a generic message from the browser. |
| 91 | + |
| 92 | +### Example |
| 93 | + |
| 94 | +1. Create an app that contains two form controls, **AccountForm** and **ContactForm**. |
| 95 | + |
| 96 | +1. Set the **App** object's **ConfirmExit** property to this expression: |
| 97 | + |
| 98 | + ```powerapps-dot |
| 99 | + AccountForm.Unsaved Or ContactForm.Unsaved |
| 100 | + ``` |
| 101 | +
|
| 102 | + This dialog box appears if the user changes data in either form and then tries to close the app without saving those changes. |
| 103 | +
|
| 104 | + > [!div class="mx-imgBorder"] |
| 105 | + >  |
| 106 | +
|
| 107 | +1. Set the **App** object's **ConfirmExitMessage** property to this formula: |
| 108 | +
|
| 109 | + ```powerapps-dot |
| 110 | + If( AccountsForm.Unsaved, |
| 111 | + "Accounts form has unsaved changes.", |
| 112 | + "Contacts form has unsaved changes." |
| 113 | + ) |
| 114 | + ``` |
| 115 | +
|
| 116 | + This dialog box appears if the user changes data in the Account form and then tries to close the app without saving those changes. |
| 117 | +
|
| 118 | + > [!div class="mx-imgBorder"] |
| 119 | + >  |
0 commit comments