How to Build a PCF Control for Dynamics 365: A Step-by-Step Guide

How to Build a PCF Control for Dynamics 365: A Step-by-Step Guide

Standard Dynamics 365 forms and views cover a lot, but sooner or later a team asks for something they cannot do: a slider instead of a number box, a visual timeline instead of a plain subgrid, or a field that checks itself as the user types. The Power Apps component framework (PCF) is Microsoft’s supported way to build these. This guide walks through building your first PCF code component, from installing the tools to seeing it on a model-driven form.

The steps follow Microsoft’s own tutorial on Microsoft Learn, which builds a simple “linear input” control: a slider bound to a number column. It is small enough to finish in an afternoon and covers every part of the process you will use on real projects.

What a PCF control is, and when to build one

A PCF control (Microsoft calls it a code component) is a piece of TypeScript that replaces how a field or a dataset is shown in a model-driven app. Field components bind to a single column. Dataset components replace a view or subgrid. Because the framework is supported by Microsoft, a well-built component behaves like a native part of the form and survives platform updates.

Build one when configuration and business rules are not enough and the problem is about how users see or enter data. If the need is about logic on the server, a plugin or a flow is usually the better tool.

Step 1: Install the prerequisites

Microsoft lists four things to install before you start:

  • Visual Studio Code, with the “Add to PATH” option selected during installation.
  • Node.js, with the LTS version recommended.
  • Microsoft Power Platform CLI, either through the Power Platform Tools extension for VS Code or the Power Platform CLI for Windows.
  • .NET build tools: the “.NET build tools” workload in Visual Studio 2022, Build Tools for Visual Studio 2022, or the .NET SDK (in which case you use dotnet build instead of msbuild).

Microsoft also recommends installing git for source control. If you later see an error that “npm” is not recognised, Node.js is missing from your path.

Step 2: Create the component project

Create an empty folder, open it in VS Code and run the pac pcf init command in the terminal. In Microsoft’s tutorial it looks like this:

pac pcf init --namespace SampleNamespace --name LinearInputControl --template field --run-npm-install

The --template parameter decides the component type: field for a single column, dataset for views and subgrids. The --run-npm-install flag installs the project’s dependencies in the same step.

Two generated files matter most:

  • ControlManifest.Input.xml describes the component: its namespace, name, version and the properties it exposes.
  • index.ts holds the TypeScript class that does the work.

Step 3: Define the manifest

The manifest is the contract between your component and Dataverse. The control element sets the namespace, constructor, version and control-type="standard", which gives your code an empty container element to draw into. Remember to increase the version number whenever you deploy changes, or the platform may keep serving the old build.

Each property element describes a value the component works with. The usage attribute is the key setting: bound ties the property to the column on the form, while input allows either a column or a static value set by the maker. In the tutorial, a type-group lets the slider bind to whole number, currency, floating point and decimal columns. Finally, the resources element lists the code file (index.ts) and any CSS or localisation files.

Step 4: Write the component logic

Your class implements four lifecycle methods. Understanding them is most of the learning curve:

  • init runs once when the component loads. Create your HTML elements here, attach event listeners and start any server calls the component needs.
  • updateView runs whenever a value in the property bag changes, for example when the record loads or another script updates the column. Read the current value from the context and refresh what the user sees.
  • getOutputs is called by the framework to collect the values your component wants to write back to bound columns. When the user changes something, you call notifyOutputChanged, and the framework then asks for the new outputs.
  • destroy runs when the component is removed. Remove event listeners and cancel pending calls here to avoid memory leaks.

In the slider example, init creates a range input and a label, updateView sets the slider position from the column value, and an input event handler calls notifyOutputChanged so that getOutputs can return the new number. Running npm run refreshTypes generates typed interfaces from your manifest, so your editor knows exactly which properties exist.

Step 5: Build and test in the test harness

Build with npm run build, then run npm start watch. This opens the test harness in your browser: a local sandbox that shows your component next to panels for context inputs (form factor, width and height), data inputs for each property, and the outputs your component returns. In watch mode, changes to your TypeScript reload the harness automatically. Changes to the manifest need a restart.

The harness is fast, but it is not Dataverse. Microsoft notes that Web API calls, paging, sorting and filtering are not available there, and that field security and read-only behaviour are not modelled. Plan to test those inside a real environment. You can debug in both places with the browser developer tools by setting a breakpoint in updateView.

Step 6: Package and deploy to Dataverse

For quick iterations, connect to your environment with pac auth create --url https://yourorg.crm.dynamics.com and run pac pcf push --publisher-prefix <your prefix>. This pushes the component straight into a development environment.

For anything that moves between environments, package it in a solution:

pac solution init --publisher-name developer --publisher-prefix dev
pac solution add-reference --path <path to your component folder>
msbuild /t:restore
msbuild

Use a publisher name and prefix that are unique in your environment. Debug builds create an unmanaged solution and release builds (msbuild /p:configuration=Release) create a managed one, which is what you should ship to test and production.

Step 7: Add the control to a form

Microsoft documents this in the classic form editor: open the table’s main form, double-click the column, go to the Controls tab and select Add Control. Pick your component, choose where it should appear (Web, Phone or Tablet) and set any properties. Then save and publish the form. Open a record and your slider replaces the standard number box.

Tips for production-ready components

  • Build for production. Use npm run build -- --buildMode production for release builds so the bundle is smaller.
  • Look native. Fluent UI with React helps your component match the rest of the app.
  • Clean up. Every listener added in init should be removed in destroy.
  • Check licensing early. Components that only use Dataverse data in model-driven apps generally run on existing licences, while components that call external services may need premium licences.

Build it yourself, or start from a ready-made control

A slider is a good first project. Real business components, such as editable grids, timelines or Gantt charts, take much more work: paging, sorting, security, accessibility and support for future platform updates. Before building from scratch, check whether a published control already solves the problem. Our Modern Smart Grid, for example, is a dataset control that brings a modern data grid experience to Dynamics 365. You can see all our products on the PCF Controls page.

When nothing off the shelf fits, our custom PCF control development service takes a component from workshop and mock-up to a managed solution in your environment, built with TypeScript, React and Fluent UI. It sits alongside our wider Dynamics 365 and Power Platform services, including plugin development for server-side logic.

Need a PCF control for your Dynamics 365 forms?

Tell us what your users are struggling with and we will tell you whether a ready-made control, a custom component or a configuration change is the right answer. Book a free consultation with Simetrix Consult.

Sources: Microsoft Learn, Create your first component, Create and build a code component, Debug code components, Package a code component and Add code components to a column or table.

Book Your Free CRM Consultation

Talk to a Dynamics 365 and Power Platform specialist.

Ready to transform your business processes? Schedule a 30-minute deep-dive session to discuss your current challenges and future goals.

  • No-obligation architectural review
  • Direct access to senior expertise
  • Preliminary solution mapping

We respect your privacy. Your data will only be used to contact you regarding your request.