Developing canvas apps in Power Apps requires adherence to coding standards to ensure maintainability, performance, and consistency. This guide summarizes key rules, guidelines, and best practices from the Power Apps Coding Standards document, helping developers create high-quality apps efficiently. This is Part 1, covering introduction, naming conventions, variable types, and commenting.
Introduction to Power Apps Canvas Coding Standards
Welcome to the comprehensive guide on Power Apps coding standards for canvas apps. This resource provides over 50 pages of essential rules, guidelines, and best practices for building robust Power Apps/Canvas apps. While Power Apps has official standards from 2018, this updated version incorporates modern techniques for better development outcomes.
"In this guide you will find 50+ pages of coding rules, guidelines and best practices to be used to create Power Apps/Canvas apps." - Power Apps Coding Standards
Naming Conventions
Consistent naming is crucial for readability and accessibility in canvas apps.
Screen Names
Screen names should describe their purpose in 2-3 words, ending with "Screen" for clarity. Use proper-case to ensure screen-readers pronounce them correctly for visually-impaired users.
| Good Examples | Bad Examples | Bad Reason |
|---|---|---|
| Appointments Screen | Appointments | Missing the word 'Screen' |
| Order Form Screen | OrderFormScreen | Not friendly to a screen reader |
| Collect Signature Screen | scrCollectSignature | Not friendly to a screen reader |
Control Names
Control names should include the control type prefix, purpose, and screen, using camel-case with underscores for spacing.
| Control | Prefix | Control | Prefix | Control | Prefix |
|---|---|---|---|---|---|
| 3D Object | 3do | Date Picker | dte | Microsoft Stream | str |
| Add Picture | pic | Drop Down | drp | PDF Viewer | |
| Address Input | add | Export | exp | Pen Input | pen |
| Audio | aud | Form | frm | Power BI Tile | pbi |
| Barcode Scanner | bar | Gallery | gal | Radio | rad |
| Button | btn | Group | grp | Rating | rtg |
| Camera Control | cam | HTML Text | htm | Rich Text Editor | rte |
| Canvas | cvs | Icon | ico | Shapes | shp |
| Card | dtc | Image | img | Slider | sld |
| Charts | chr | Import | imp | Table | tbl |
| Check Box | chk | Label | lbl | Text Input | txt |
| Collection | col | List Box | lst | Timer | tmr |
| Container | con | Map | map | Toggle | tgl |
| Combo Box | cmb | Measuring Camera | mcm | Video | vid |
| Component | cmp | Microphone | mic |
| Good Examples | Bad Examples | Bad Reason |
|---|---|---|
| drp_NewEmployee_Department | drpDepartmentNewEmployee | No spacing |
| btn_OrderForm_Submit | btn_Submit_OrderForm | Wrong order |
| gal_Home_Appointments | gly_Home Appointments | Non-standard control prefix |
Variable Names
Variable names should indicate scope and purpose, using camel-case without spaces. Avoid data types in names and ensure descriptiveness.
| Good Examples | Bad Examples | Bad Reason |
|---|---|---|
| gblUserCurrent | UserCurrent | No scope |
| locPacksInBoxQuantity | Loc_Packs_In_Box_Quantity | Improper capitalization and spacing |
| LocIsLoading | locBoolLoading | Do not use data types in variable names |
| varWorkdaysDuringVacation | varWorkdays | Not descriptive enough |
Collection Names
Collection names should include the original datasource abbreviation and purpose, using camel-case.
| Original Datasource | Abbreviation |
|---|---|
| Dataverse | Dv |
| SharePoint | Sp |
| SQL | Sql |
| Salesforce | Sf |
| None (created in-app) | (none) |
| Good Examples | Bad Examples | Bad Reason |
|---|---|---|
| colSpEmployees | colEmployees | No datasource |
| colDvSalesLeads | coldv_salesleads | Improper capitalization and spacing |
| colNavigationMenu | NavigationMenu | Do not use data types in variable names |
Datasource Table Names
Datasource tables should use 1-3 words in singular form and proper-case for conciseness and clarity.
| Good Examples | Bad Examples | Bad Reason |
|---|---|---|
| Employee | Emp | Abbreviation instead of full word |
| Construction Projects | Projects | Too general, what type of projects? |
| Repair Orders | RepairOrders | No spacing, plural |
Variable Type Standards
Choose variable types based on scope to optimize performance and maintainability.
Variable Scope
| Variable Type | Declaration Method | Variable Scope |
|---|---|---|
| Global | Set Function | Available across all app screens |
| Local | UpdateContext Function | Available on a single app screen |
| One-time | With Function | Available within the With function |
Why Use Both Local and Global Variables
Using only global variables in large apps complicates impact assessment across screens, leading to bugs. Local variables limit scope to one screen for easier management. One-time variables clear from memory post-execution, reducing overhead.
Usage Examples
powerapps// Global variable Set( gblSalesTaxAmount, Value(txt_OrderForm_SubtotalAmount.Text) * 0.13 ); // Local variables UpdateContext( { locLineItemsCount: 0, locShowConfirmationMenu: false, locOrderFormMode: Blank() } ); // One-time variable With( {varBusinessContact: LookUp('Sales Orders', ID=ThisItem.ID)}, Concatenate( varBusinessContact.FirstName, " ", varBusinessContact.LastName ) );
Commenting Code
Good comments explain intent, not just code actions.
Tips for Writing Good Comments
- Write comments describing code section intent (goal).
- Avoid restating code lines; focus on clean code.
- Update comments with code changes.
- Avoid excessive comments that are hard to maintain.
- Use full sentences and plain language.
- Avoid abbreviations, acronyms, or slang.
Line Comments vs. Block Comments
| Comment Style | Syntax | Example |
|---|---|---|
| Line | // [comment goes here] | // Validate the work order to ensure it will not be rejected upon submission. |
| Block | /* [comments go here] */ | /* Work Order Details Screen: - Uses a single form to create, edit and view a record to minimize the number of controls in the app - Emails a signed PDF to the manager after the form is submitted so it can be stored as backup */ |
Commenting Style
- Place comments above the code section on separate lines.
- Avoid in-line comments on the same line.
- Start with a capital letter.
- End with a period.
powerapps// Validate the work order to ensure it will not be rejected upon submission. Set( varValidateForm, Validate( 'Work Orders', Defaults('Work Orders'), gblRecordWorkOrder.Current ) );