Study guide
6.3 Variables (Context, Global), Collections & State Management
Microsoft Power Platform Functional Consultant PL-200
Track your progress as you read
Finished sections get a check mark.
1 Chapter 1: Dataverse Tables, Relationships & Core Columns
1.1 Dataverse Table Types, Properties & Ownership 1.2 Table Relationships & Cascading Rules 1.3 Column Types, Formats, Primary Keys & Alternate Keys 1.4 Rollup, Calculated & Formula Columns with Power Fx
2 Chapter 2: Dataverse Data Management & Governance
2.1 Dataverse Search, Quick Find & Relevance Indexing 2.2 Auditing Configuration & Log Management 2.3 Duplicate Detection Rules & Settings 2.4 Bulk Record Operations, Data Import, Export & Templates
3 Chapter 3: Dataverse Security Model & Access Control
3.1 Business Units, Ownership Models & Modern BU Matrix 3.2 Security Roles, Privileges & Depth Levels 3.3 Teams Architecture: Owner, Access, and Microsoft Entra (AAD) Group Teams 3.4 Column-Level Security & Hierarchy Security Models
4 Chapter 4: Model-Driven App Fundamentals & Information Architecture
4.1 Model-Driven App Design, Site Map Navigation & Modern App Designer 4.2 Form Types: Main, Quick Create, Quick View & Card Forms 4.3 View Configuration, System Views, Personal Views & Filters
5 Chapter 5: Advanced Model-Driven App Components & Custom Pages
5.1 Custom Pages & Modern Commanding with Power Fx 5.2 Form Component Controls & Specialized UX Elements 5.3 Embedding Canvas Apps in Model-Driven Forms 5.4 Embedding Power BI Reports, Dashboards & Tiles
6 Chapter 6: Canvas Apps Structure, Formulas & Data Operations
6.1 Canvas App Architecture, Screens, Containers & Controls 6.2 Power Fx Formulas, Delegation & Data Source Limits 6.3 Variables (Context, Global), Collections & State Management 6.4 Triggering Power Automate Cloud Flows from Canvas Apps
7 Chapter 7: Power Pages Site Design, Navigation & Content
7.1 Power Pages Design Studio & Site Structure 7.2 Power Pages Templates, Styling & Responsive Layouts 7.3 Web Pages, Navigation Menus & Content Snippets
8 Chapter 8: Power Pages Data Integration, Forms & Web Roles
8.1 Power Pages Lists, Basic Forms & Advanced Forms 8.2 Table Permissions, Web Roles & Page Access Security 8.3 External Identity Providers & Authentication Configuration
9 Chapter 9: Power Automate Cloud Flow Fundamentals & Triggers
9.1 Cloud Flow Types: Automated, Instant, Scheduled & Desktop Overview 9.2 Dataverse Connector Triggers & Operational Filters 9.3 Standard Connectors, Custom Connectors & Connection References
10 Chapter 10: Cloud Flow Actions, Expressions & Logic Controls
10.1 Logic Controls: Conditions, Switches, Apply to Each & Do Until Loops 10.2 Variables, Data Operations & Dynamic Content Manipulation 10.3 Power Automate Expression Language (WDL / Functions) 10.4 Error Handling, Configure Run After & Scope Controls
11 Chapter 11: Business Process Flows & Guided Processes
11.1 Business Process Flow Architecture, Stages, Steps & Data Steps 11.2 Branching Rules & Multi-Entity Business Process Flows 11.3 BPF Action Steps, Workflows & Cloud Flow Execution 11.4 BPF Security Roles, Order & Process Lifecycle
12 Chapter 12: Classic Workflows, Business Rules & Modern Logic Extensibility
12.1 Classic Dataverse Workflows: Real-Time vs. Background (Async) 12.2 Business Rules: Scope & Actions 12.3 Low-Code Plug-ins in Dataverse: Automated vs. Instant 12.4 Troubleshooting Automations, Run History & Analytics
13 Chapter 13: Power Platform Environment Architecture & Security
13.1 Environment Types: Default, Sandbox, Production, Trial, Developer 13.2 Environment Governance, Groups, Routing & Capacity Management 13.3 Data Loss Prevention (DLP) Policies & Connector Classifications
14 Chapter 14: Application Lifecycle Management (ALM) & Solutions
14.1 Unmanaged vs. Managed Solutions & Solution Layering Mechanics 14.2 Solution Components, Dependencies, Publishers & Prefixes 14.3 Exporting, Importing, Upgrading & Patches 14.4 Solution Checker, App Checker & ALM Best Practices
15 Chapter 15: Enterprise Interoperability & Service Integration
15.1 Exchange / Server-Side Synchronization & Email Integration 15.2 SharePoint & OneDrive Document Management Integration 15.3 Microsoft Word & Excel Document Templates
16 Chapter 16: Copilot, AI Capabilities & Exam Strategy
16.1 Copilot Studio & Generative AI across Power Platform 16.2 AI Builder Prebuilt & Custom Models in Apps and Flows 16.3 PL-200 Exam Strategy, Time Management & Question Analysis
6.3 Variables (Context, Global), Collections & State Management
Key Takeaways Explain This Topic AI
Context variables created via UpdateContext({locVar: value}) are strictly scoped to the screen where they are declared and can be passed across screens via the Navigate() function.
Global variables created via Set(gblVar, value) are app-scoped and accessible across all screens, ideal for user profiles, theme tokens, and global application state.
Collections created via ClearCollect(), Collect(), and manipulated via Patch(), Remove(), and UpdateIf() provide in-memory tabular structures for caching, shopping carts, and multi-record staging.
Canvas app state should follow declarative principles: makers should bind directly to control properties and data sources where possible, reserving variables for true stateful transitions.
Offline capability can be implemented using SaveData() and LoadData() to serialize in-memory collections to encrypted local device storage, synchronized back via Connection.Connected event triggers.
Last updated: August 2026
Variables (Context, Global), Collections & State Management
State management is the backbone of dynamic, interactive canvas applications. While Power Apps encourages a declarative, formula-first paradigm, enterprise applications frequently require maintaining transient user state—such as tracking multi-step wizard progress, managing offline shopping carts, buffering uncommitted records, and storing user authorization profiles. For the PL-200: Microsoft Power Platform Functional Consultant exam, you must master the differences, scope, lifecycles, and performance implications of Context Variables , Global Variables , Collections , and local storage caching via SaveData and LoadData .
1. The Three Tiers of Canvas App State
Power Apps provides three distinct state containers, each scoped to a specific architectural layer. +-----------------------------------------------------------------------------+
- | CANVAS APP STATE MANAGEMENT TIERS |
- | |
- | +---------------------------------------------------------------------+ |
- | | 1. CONTEXT VARIABLES (Screen Scoped) | |
- | | - Created via: UpdateContext({ locFilter: "Active", locStep: 2 })| |
- | | - Accessible ONLY on the screen where declared | |
- | | - Passed between screens via: Navigate(Target, None, { ... }) | |
- | +---------------------------------------------------------------------+ |
- | |
- | +---------------------------------------------------------------------+ |
- | | 2. GLOBAL VARIABLES (App Scoped) | |
- | | - Created via: Set(gblCurrentUser, User()) | |
- | | - Accessible across ALL screens in the entire application | |
- | | - Stores scalar values, records, or objects | |
- | +---------------------------------------------------------------------+ |
- | |
- | +---------------------------------------------------------------------+ |
- | | 3. COLLECTIONS (In-Memory Tabular Store) | |
- | | - Created via: ClearCollect(colCart, Table), Collect(colCart, {})| |
- | | - Full 2-dimensional table stored in client device RAM | |
- | | - Manipulated via: Patch, Remove, RemoveIf, UpdateIf | |
- | +---------------------------------------------------------------------+ |
- +-----------------------------------------------------------------------------+
- Comparative Architectural Matrix
Dimension Context Variables Global Variables Collections
Creation Function UpdateContext({ locVar: value }) Set(gblVar, value) ClearCollect(col, ...) , Collect(col, ...)
- Scope Single Screen Entire App (All screens) Entire App (All screens)
- Data Structure Scalar, Record, or Table Scalar, Record, or Table Tabular Data (Rows & Columns)
- Memory Location Screen Context Memory Application Session RAM Application Session RAM
Navigation Passing Supported via Navigate() third parameter Not required (globally visible) Not required (globally visible)
Offline Serialization Not directly serializable Not directly serializable Supported via SaveData() / LoadData()
Standard Naming Prefix loc (e.g., locIsSubmitting ) Prefix gbl (e.g., gblUserRole ) Prefix col (e.g., colPendingOrders )
2. Context Variables ( UpdateContext )
Context variables hold state specific to a single screen. They cannot be directly read or modified by controls on another screen.
Syntax and Behavioral Mechanics
Context variables are declared using a record syntax containing key-value pairs wrapped in curly braces ( {} ): // Updating multiple context variables in a single formula
- UpdateContext({
- locShowConfirmDialog: true,
- locSelectedTab: "Equipment",
- locValidationErrors: 0
- })
- Passing Context Across Screens via Navigate()
You can initialize or update context variables on a target screen during navigation by utilizing the optional third parameter of Navigate() : Navigate(
- WorkOrderEditScreen,
- ScreenTransition.None,
- {
- locCurrentWorkOrderId: Gallery_WorkOrders.Selected.WorkOrderId,
- locFormMode: FormMode.Edit,
- locSourceScreen: "Dashboard"
- }
- )
When WorkOrderEditScreen opens, locCurrentWorkOrderId is immediately available in memory before OnVisible executes.
Resetting Context Variables
To clear or reset a context variable, update its value to Blank() or its default primitive: UpdateContext({ locShowConfirmDialog: false, locSelectedRecord: Blank() })
3. Global Variables ( Set )
Global variables hold state across the entire application lifecycle. Once defined, any control or formula across any screen can read and modify the variable.
Syntax and Usage
Global variables are created and updated using the Set(VariableName, Value) function: // Storing a scalar string
Set(gblEnvironmentName, "Production");
- // Storing a complete Dataverse record
- Set(gblCurrentAccount, LookUp(Accounts, AccountId = GUID("a1b2c3d4-...")));
- // Storing an object or complex record
- Set(gblUserSession, {
- FullName: User().FullName,
- Email: User().Email,
- Role: LookUp(UserSecurityRoles, UserEmail = User().Email).RoleName,
- LoggedInAt: Now()
- });
Note
Declarative Best Practice: Do not overuse global variables. If a value can be derived directly via a formula (e.g., Label1.Text = Gallery1.Selected.AccountName ), bind directly to Gallery1.Selected.AccountName rather than creating a global variable on Gallery1.OnSelect . Unnecessary variables increase memory overhead and make debugging difficult.
4. Collections: In-Memory Tabular Data
Collections are temporary, in-memory database tables that exist in client RAM during the user's active session. They provide full two-dimensional tabular capabilities, allowing you to add, edit, filter, sort, and remove rows locally without making immediate backend network calls. +-----------------------------------------------------------------------------+
- | COLLECTION MANIPULATION PIPELINE |
- | |
- | 1. POPULATE / RESET: |
- | ClearCollect(colOrderItems, Filter(Products, Category = "Hardware")) |
- | |
- | 2. APPEND NEW ITEM: |
- | Collect(colOrderItems, { ItemId: "H-99", Qty: 1, Price: 29.99 }) |
- | |
- | 3. UPDATE SPECIFIC ROW(S): |
- | UpdateIf(colOrderItems, ItemId = "H-99", { Qty: 3 }) |
- | |
- | 4. REMOVE ITEM: |
- | Remove(colOrderItems, ThisItem) |
- | |
- | 5. BATCH SUBMIT TO DATAVERSE: |
- | ForAll(colOrderItems, Patch(OrderDetails, Defaults(OrderDetails), { ...}))|
- +-----------------------------------------------------------------------------+
- Core Collection Functions
Function Syntax Operational Purpose
ClearCollect ClearCollect(CollectionName, Item1, [Item2, ...]) Clears all existing rows from the collection and inserts the new records or table.
Collect Collect(CollectionName, Item1, [Item2, ...]) Appends one or more rows to the existing collection without deleting current data.
Clear Clear(CollectionName) Empties the collection completely, leaving a schema with 0 rows.
Remove Remove(CollectionName, Record1, [Record2, ...]) Removes specific row records from the collection. Inside a gallery, use Remove(colData, ThisItem) .
RemoveIf RemoveIf(CollectionName, ConditionFormula) Evaluates a condition against every row and deletes all matching records (e.g., RemoveIf(colCart, Quantity <= 0) ).
UpdateIf UpdateIf(CollectionName, ConditionFormula, { Field: NewVal }) Finds all rows satisfying the condition and modifies the specified column values.
Patch Patch(CollectionName, TargetRecord, { Field: NewVal }) Modifies an existing row or inserts a new row using Defaults(CollectionName) .
Batch Submitting Collections to Dataverse
Collections are frequently used to stage line items (e.g., invoice lines, time sheet entries, inspection checklists) locally before committing them in bulk to Dataverse: // Submitting an entire collection of line items to Dataverse
- ForAll(
- colOrderLines As LineItem,
- Patch(
- OrderLines,
- Defaults(OrderLines),
- {
- 'Order Header': gblNewOrderHeaderRecord,
- Product: LookUp(Products, ProductId = LineItem.ProductId),
- Quantity: LineItem.Qty,
- UnitPrice: LineItem.Price,
- ExtendedAmount: LineItem.Qty * LineItem.Price
- }
- )
- );
- Clear(colOrderLines);
- Notify("All order lines successfully submitted!", NotificationType.Success);
- 5. Offline Caching with SaveData , LoadData & ClearData
For canvas apps deployed to mobile frontline workers (field technicians, warehouse operators, pipeline inspectors) operating in low-connectivity or air-gapped environments, Power Apps enables manual offline caching. +-----------------------------------------------------------------------------+
- | OFFLINE DATA CACHING LIFECYCLE |
- | |
- | [APP STARTUP] |
- | | |
- | v |
- | If(Connection.Connected, |
- | // ONLINE: Refresh from Dataverse & Cache Locally |
- | ClearCollect(colWorkOrders, Filter(WorkOrders, Owner = User().Email));|
- | SaveData(colWorkOrders, "LocalWorkOrdersCache"), |
- | // OFFLINE: Load from Device Encrypted Sandbox Storage |
- | LoadData(colWorkOrders, "LocalWorkOrdersCache", true) |
- | ) |
- | |
- | [OFFLINE EDITS] |
- | Technician modifies records in colWorkOrders -> SaveData(colWorkOrders, ..)|
- | |
- | [RECONNECTION EVENT (Connection.Connected = true)] |
- | Iterate through offline queue -> Patch to Dataverse -> Clear offline queue|
- +-----------------------------------------------------------------------------+
- Caching Functions
SaveData(CollectionName, "CacheKeyName") : Serializes an in-memory collection and writes it to encrypted local sandbox storage on iOS, Android, or Windows Power Apps mobile player.
LoadData(CollectionName, "CacheKeyName", [IgnoreNonexistentFile]) : Reads the serialized data from device storage and reconstructs the collection in memory. Setting IgnoreNonexistentFile to true prevents errors on initial app launch before a cache file has been created.
ClearData("CacheKeyName") : Purges the specified local cache file from device storage.
Detecting Connectivity
Connection.Connected : Returns a boolean ( true if connected to network, false if disconnected).
Connection.Metered : Returns a boolean ( true if connected via a metered cellular connection, allowing apps to defer heavy media downloads).
Warning
Platform Restriction: SaveData() and LoadData() operate inside the Power Apps Mobile Player on mobile devices and the Windows desktop player. They do not persist data when running inside standard web browsers in Power Apps Studio preview.