MSBA-271 · Lesson 8 of 12 · 19 min

Building Power Apps code apps

▶ Video coming soon A video version of this lesson is on the way.

Hamza Ferriday, the athletics equipment manager, ran the equipment room under the gym with a clipboard and a spreadsheet. Students and teams borrowed balls, bibs, timing gates, rowing ergometers and first-aid kits, and returns were tracked by memory as much as by paper. He had seen the facilities team's apps and asked for one of his own, with two requirements: it had to be fast on the tablet at the counter, and it had to look like the athletics department's own website, not like a form. Signe heard the second requirement and said, "That one is a code app."

What a code app is

A Power Apps code app is a web application written by a developer, in a framework of their choice such as React with TypeScript and Vite, that runs as a Power Apps app. The developer writes the whole user interface in code, as on any web project. Power Platform supplies the rest: Microsoft Entra sign-in, access to connectors and Dataverse through the Power Apps client library, sharing and licensing like other apps, and governance such as data loss prevention policies, Conditional Access and App Quarantine. Code apps became generally available in February 2026.

The difference from a code component is scope. A code component, from lessons 5 to 7, is one control placed inside an app that someone else built. A code app is the whole app. The difference from a canvas app is authorship: a canvas app is built in a designer with Power Fx, while a code app is built in an editor with code, versioned in Git and built with npm like other web projects.

A diagram. On the left, stacked boxes: the app code in React or Vue with TypeScript, then the Power Apps SDK client library and generated services, and below them a note that the app is built locally and published with the Power Apps CLI. A two-way arrow links the client library to a Power Platform host box on the right, which contains Microsoft Entra sign-in, connectors and connections, Dataverse tables and APIs, cloud flows and agents, and data policies, sharing and monitoring.
A code app: the developer's web project, the client library and generated services, and the platform behind them.
Where a code app fits among the ways to build.
QuestionCanvas appCode componentCode app
Who builds itMakers in a designerDevelopers in an editorDevelopers in an editor
LanguagePower FxTypeScript, often ReactTypeScript or JavaScript, any web framework
ScopeWhole appOne control inside an appWhole app
Data accessConnectors and Dataverse in the designerThrough the context objectGenerated services over connectors and Dataverse
Source controlPower Platform Git integration or solution exportGit, as a web projectGit, as a web project
Good fitMost business appsA better control for an existing appA custom user experience with full control of the interface

Signe was careful about when to choose one. "Most apps at Lumenvale should be canvas or model-driven apps. A code app makes sense when the interface is the point, when there is a developer to maintain it, and when the team already works in a web stack." Hamza's app passed all three tests: the athletics website was built in React by the communications office, the interface had to match it, and Wiremu would own the code with Signe as reviewer.

Before building: what the environment needs

Code apps have prerequisites that a developer cannot meet alone. An administrator must turn code apps on for the environment, under environment Settings, Product, Features. Users who run code apps need a license that covers premium features, such as a Power Apps Premium license, pay-as-you-go, an App Pass, or an eligible Dynamics 365 license, because code apps are treated as premium apps. Rupert's governance team enabled code apps in Wiremu Dev, Facilities Dev and Facilities Test and recorded the change, and Octavia confirmed that the athletics staff who would use the app already had premium licenses through the facilities program.

The developer's machine needs Node.js and the command-line tools. Microsoft's current guidance uses the Power Apps CLI that ships in the npm package @microsoft/power-apps, the Power Apps SDK, from version 1.0.4. Its commands begin with pa. The older pac code commands in the Power Platform CLI still exist, but are marked as preview and due to be deprecated in a future release, so new projects should use the npm tool. Command names have changed during the preview, so it is worth checking the current reference before starting.

The main commands. The pac code commands are preview and will be deprecated; check the current reference for exact options.
TaskPower Apps CLI (npm)Older pac code command
Sign inpa auth loginpac auth create
Set up a project as a code apppa app initpac code init
Add a connector or Dataverse tablepa app add data-sourcepac code add-data-source
Run locally against real datapa app runpac code run
Publish to the environmentpa app pushpac code push

Starting the project

Wiremu began with an ordinary web project. He created a React and TypeScript project with Vite, as he would for any web app, installed the Power Apps SDK, signed in and initialized the project as a code app in Wiremu Dev. Initializing writes a small configuration file that records the app's name, the environment and the data sources, and the SDK adds what the app needs to start inside Power Apps.

Creating a React project and initializing it as a code app. Options vary between releases; check the current CLI reference.
npm create vite@latest athletics-loans -- --template react-ts
cd athletics-loans
npm install
npm install @microsoft/power-apps
npx pa auth login
npx pa app init --display-name "Athletics Equipment Loans"

From there the work is web development. Wiremu borrowed the athletics website's colors, fonts and header from the communications office's design files, built a counter screen with a search box and large buttons for the tablet, and wrote components for the item list, the borrower panel and the return screen. None of that needed Power Platform at all. The platform came in where the app needed data.

Connecting to data

A code app reaches data through data sources added with the CLI. Adding a data source generates TypeScript code in the project: a model describing the table or connector's data and a service with methods to call it. The app calls the generated service; the service calls the Power Apps client library; the library calls the platform with the signed-in user's identity. The developer never handles tokens or connection strings.

Adding two Dataverse tables. Each generates a model and a service under src/generated.
npx pa app add data-source --connector dataverse --table lcc_equipmentitem
npx pa app add data-source --connector dataverse --table lcc_equipmentloan

Hamza's data lived in two new Dataverse tables in a new Athletics Equipment solution that depended on Lumenvale Core: Equipment Item, with name, category, tag number and status; and Equipment Loan, with a lookup to the item, the borrower, the team, the due date and the returned date. The generated services gave Wiremu methods to create, retrieve, list, update and delete rows, with options for selecting columns, filtering, sorting and paging.

Calling a generated Dataverse service from the app. The service handles sign-in and the Web API call.
import { Lcc_equipmentloansService } from "./generated/services/Lcc_equipmentloansService";

export async function loansDueToday(today: string) {
    const result = await Lcc_equipmentloansService.getAll({
        select: ["lcc_name", "lcc_borrower", "lcc_duedate"],
        filter: "lcc_duedate eq " + today + " and lcc_returnedon eq null",
        orderBy: ["lcc_duedate asc"],
        maxPageSize: 50,
    });
    return result.data ?? [];
}

Generated services cover the common cases but not everything. Microsoft's documentation for code apps and Dataverse lists limits such as polymorphic lookups, FetchXML, alternate keys and changes to the table schema, which the generated services do not support. Wiremu checked that list before designing. The Equipment Loan table's borrower was a lookup to Contact only, not a polymorphic customer lookup, partly because of it.

Other data sources work the same way. A code app can add standard and custom connectors, such as Office 365 Users to look up a borrower's name, using connections the user signs in to. It can call Dataverse custom actions and functions, start Power Automate cloud flows that the app adds as data sources, and call Copilot Studio agents. It can read environment variables so that settings, such as the overdue reminder days, differ between Wiremu Dev, Facilities Test and Lakeshore Ops. Each of these appears in the AB-400 skills outline.

How the athletics loans app reaches data and services.
Need in the loans appHow the code app meets it
List and update items and loansGenerated Dataverse services for the two tables
Show the borrower's photo and departmentThe Office 365 Users connector
Send an overdue reminder by emailA Power Automate cloud flow added as a data source and started from the app
Answer staff questions about loan rulesA Copilot Studio agent, planned for a later release
Change the loan period without a releaseAn environment variable read at startup

Running locally

During development the app runs on the developer's machine against real platform data. The run command starts the local web server and a Power Apps host page that signs the developer in and loads the local app inside it, so the app's data calls go to Wiremu Dev with Wiremu's own identity and permissions. Changes to the code reload in the browser as in any Vite project.

Because the app runs as the signed-in user, Dataverse security applies during development exactly as it will for real users. Wiremu learned this when a test borrower could not be created: his security role in Wiremu Dev lacked create permission on Equipment Loan. The fix was the role, not the code, and the same role became the athletics staff role for test and production.

Designing for the counter

Hamza's first requirement, speed at the counter, shaped the design more than the technology did. Staff scan or type a tag number, see the item and its status, and lend or return it in two taps. Wiremu kept the list of items in memory after the first load, filtered it locally as staff typed, and only called Dataverse to save a loan or a return. He used optimistic updates for returns, showing the item as returned at once and rolling back with a message if the save failed. Lesson 9 returns to performance and to measuring it.

The second requirement, the athletics look, was easy because the interface was ordinary React. Ingrith Varsamis, who would review accessibility in lesson 10, asked only that the colors be checked for contrast and that the large buttons keep visible focus outlines. Wiremu also used semantic HTML elements for headings, lists and buttons, which helped both.

Worked problem

Choosing between a canvas app and a code app

Octavia asks why the loans app is not a canvas app, since the facilities team has built many. What is the honest answer, and what risk does a code app add?

Show solution
  1. Name the reasons: the interface must match the athletics website, the team has a developer who owns the code, and the counter workflow benefits from a fully custom, fast interface.
  2. Name the platform features that still apply: Entra sign-in, Dataverse security, connectors, sharing, licensing, DLP and Conditional Access.
  3. Name the risk: maintenance needs a developer with web skills. A canvas app could be changed by makers; a code app cannot.
  4. Name the mitigation: the code is in Git with Signe as reviewer, and the documentation explains how to build and release it.

Answer: A code app fits because the interface is the point and a developer owns it. The cost is that every change needs a developer, which Lumenvale accepted for this one app and recorded in the facilities app inventory.

Repository and team conventions

The loans app joined the facilities repository as its own folder, with the same conventions as the rest: TypeScript in strict mode, linting in the build, pull requests with Signe as reviewer, and a short README explaining how to install, sign in, run locally and release. Generated code from data sources was committed, because the app does not build without it, but was never edited by hand; when a table changed, Wiremu regenerated the service rather than patching it. Configuration that differed by environment lived in environment variables in the solution, not in files in the repository, and nothing secret was ever stored in the app, because a code app's code runs in the browser where anyone can read it.

Common mistakes

  • MistakeChoosing a code app for an ordinary form-based app.

    InsteadUse model-driven or canvas apps unless the custom interface is the point and a developer will maintain the code.

  • MistakeStarting a new project with the pac code commands.

    InsteadUse the npm-based Power Apps CLI; the pac code commands are preview and will be deprecated.

  • MistakeExpecting the generated Dataverse service to support every query.

    InsteadCheck the documented limits, such as FetchXML and polymorphic lookups, before designing.

  • MistakeBuilding before the environment allows code apps.

    InsteadAsk an administrator to turn on code apps and confirm users' licenses first.

  • MistakeHard-coding settings that differ between environments.

    InsteadRead environment variables.

By the end of the session the athletics equipment loans app ran in Wiremu Dev against real tables, with a counter screen, a return screen and a list of loans due today. Hamza tried it on the counter tablet through a link Wiremu shared and asked for one change: a larger tag number field. It was a one-line CSS change, which pleased everyone. Publishing, sharing, security and monitoring came next.

Summary and key terms

  • A code app is a whole web app written in code, such as React with TypeScript, that runs as a Power Apps app with platform sign-in, data access and governance.
  • Choose one when the custom interface is the point and a developer will maintain it; most apps should still be canvas or model-driven.
  • An administrator must enable code apps in the environment, and users need premium-level licenses.
  • Use the npm-based Power Apps CLI (pa commands); the pac code commands are preview and will be deprecated.
  • Data sources generate models and services for Dataverse tables, connectors, flows and agents; read environment variables for settings.
  • The app runs as the signed-in user, so Dataverse security applies in development as in production.
Code app
A web app written in code that runs as a Power Apps app with platform services.
Power Apps client library
The library through which a code app reaches connectors and Dataverse with the user's identity.
Power Apps CLI
The npm-based command-line tool in the Power Apps SDK, with commands beginning pa.
Data source
A connector, table, flow or agent added to a code app, which generates code to call it.
Generated service
TypeScript code created for a data source, with methods to read and change data.
Environment variable
A solution component holding a setting that can differ between environments.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Name two prerequisites that the developer cannot meet alone.

    Show answer

    An administrator must enable code apps in the environment, and users need licenses that cover premium apps.

  2. What does adding a Dataverse table as a data source produce in the project?

    Show answer

    A generated model describing the table and a service with methods to create, read, list, update and delete rows.

  3. Why did a missing security role privilege stop Wiremu during local development?

    Show answer

    The app runs as the signed-in user, so Dataverse security applies even when running locally.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz