Skip to content
MyAppBuilder
StableGuide

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

KindLifetimeUse it forRead withChange with
App stateThe whole visit (optionally remembered in the browser)A selected branch or location, a cart, a global filterApp state › key, {{state.key}}Set state / Increment state (scope App)
Page stateWhile the page is open; resets on leavingSelected tab, wizard step, a togglePage state › key, {{pageState.key}}Set state (scope Page)
Component stateWhile the component is on screenA search box's text, a dialog's open flag, a table's pageComponent state › Name › key, {{component.<id>.key}}Set state (scope Component) or the user interacting
SessionWhile signed inWho the visitor isCurrent user › id/email/name/role/isAuthenticated, {{user.…}}Sign in / Sign out actions
URLAs long as the address is the sameThe record id, optional filtersPage 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):

  1. 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.
  2. 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.
  3. 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

Example
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 :id instead.
  • Relying on browser-remembered state for security: it is a convenience; permissions remain on the server.

Related

Was this helpful?