State
State is what your app remembers while someone uses it: the location they selected, the tab that is open, the text in a search box, who is signed in, which record the address points at. MyAppBuilder has five kinds of state, each with a clear lifetime and a place in the data picke
State is what your app remembers while someone uses it: the location they selected, the tab that is open, the text in a search box, who is signed in, which record the address points at. MyAppBuilder has five kinds of state, each with a clear lifetime and a place in the data picker, and actions to change the ones you own. Choosing the right kind keeps pages simple and predictable.
When to use
| Kind | Lifetime | Use it for | Read with | Change with |
|---|---|---|---|---|
| App state | The whole visit (optionally remembered in the browser) | A selected branch or location, a cart, a global filter | App state › key, {{state.key}} | Set state / Increment state (scope App) |
| Page state | While the page is open; resets on leaving | Selected tab, wizard step, a toggle | Page state › key, {{pageState.key}} | Set state (scope Page) |
| Component state | While the component is on screen | A search box's text, a dialog's open flag, a table's page | Component state › Name › key, {{component.<id>.key}} | Set state (scope Component) or the user interacting |
| Session | While signed in | Who the visitor is | Current user › id/email/name/role/isAuthenticated, {{user.…}} | Sign in / Sign out actions |
| URL | As long as the address is the same | The record id, optional filters | Page parameters, Query parameters, {{params.id}}, {{query.key}} | Go to page with parameters |
App and page state
Define variables under Logic → App state (switch to Page state and choose the page for page variables):
- Click Add variable. Give it a key (letters, digits, underscore), a type (Text, Number, Yes / no, JSON object, List), an optional default value and a description.
- Tick Remember in the visitor's browser for app state that should survive reloads (a chosen location). The table marks such variables saved in browser.
- Use Set state actions to change it: choose the scope, the key and the value (fixed or dynamic). Increment state adds to a number.
Renaming a key breaks bindings that use the old name, so name variables carefully.
Component state
Components that hold a value expose it automatically: inputs expose value, tables and lists expose page, total and pageSize, dialogs expose open, a detail view exposes its record. Give components names so the picker reads Search box › value rather than a type. Business components use this to open their New … dialogs (Set state › dialog › open = true).
Session state
The signed-in user is available everywhere as Current user. isAuthenticated is false for public visitors, whose email and name are empty — which is why own-records rules deny access rather than match empty values.
URL state
Route parameters and query parameters are state that lives in the address, so it survives refresh and can be shared. See Routes and parameters.
Examples
Branch selector (App state) Variable: selectedBranch · Text · remembered in browser Select input (onChange) → Set state · App · selectedBranch = Event › value Jobs table filter: Branch is App state › selectedBranch Tabs on a customer page (Page state) Variable: tab · Text · default "overview" Buttons → Set state · Page · tab = "invoices" Invoices section visibility: Page state › tab is "invoices" Open a dialog (Component state) Button "Add job" → Set state · Component · New job dialog · open = true
Common mistakes
- Using app state for a tab: it leaks to other pages; use page state.
- Expecting page state to survive navigation: it resets; use app state or the URL.
- Storing the current record in state: bind the component to the record through its Data tab or the page's
:idinstead. - Relying on browser-remembered state for security: it is a convenience; permissions remain on the server.