Book Image

Extending Microsoft Power Apps with Power Apps Component Framework

By : Danish Naglekar
Book Image

Extending Microsoft Power Apps with Power Apps Component Framework

By: Danish Naglekar

Overview of this book

Power Apps Component Framework is used by professional developers to extend the capabilities of model-driven and canvas apps. Extending Microsoft Power Apps with Power Apps Component Framework will take you through the basic as well as advanced topics using practical examples. The book starts by helping you understand the fundamentals of the framework, its lifecycle, and the tools that you'll use to build code components using best practices and file management guidelines. You'll then learn how to extend Power Apps step by step and apply the principles and concepts covered in the book to build code components for field type attributes. The book covers different ways of debugging code components and guides you through the process of building code components for datasets. You'll also explore the functions and methods provided by the framework to enhance your controls using powerful sets of libraries and extensions. As you advance, you'll get to grips with creating and managing authentication profiles, discover different ways of deploying code components, and configure code components in model-driven and canvas apps. Finally, you'll learn some of the important features of the framework and learn modern web development practices. By the end of this Power Apps book, you'll be able to build, debug, enrich, and deploy code components confidently.
Table of Contents (18 chapters)
1
Section 1: Fundamentals of the Power Apps Component Framework
6
Section 2: Building and Managing Code Components
12
Section 3: Enhancing Code Components and Your Development Experience

Overview of the Power Apps component framework

This section is all about gradually familiarizing ourselves with the framework. Let's first understand what exactly the Power Apps component framework is and why we need it. It is important to understand how the Power Apps component framework evolved before we move on to learning about the differences between the Power Apps component framework and HTML web resources, as well as the licensing requirements and the advantages of using this framework.

What is the Power Apps component framework?

The Power Apps component framework, otherwise known as PCF, is defined by Microsoft as a framework that empowers professional developers and app makers to create code components for model-driven apps and canvas apps to provide enhanced user experience for users to work with data on forms, views, and dashboards. But what does that mean? It means that now professional developers can create widgets that can be configured by the system customizer or an app maker easily, extending the capabilities of any application. Some examples include transforming a numeric field into a slider or transforming a list of appointments into an entirely different visual, such as a calendar.

Originally, it was named Custom Control Framework (CCF) and later renamed to Power Apps Control Framework, but that name did not stick for too long and it was finally renamed to the Power Apps component framework (PCF). Before releasing this framework for public use, Microsoft was using it internally to create a lot of components on a unified interface, one such component being editable grids.

PCF allows professional developers to use a multitude of libraries and services of their choice and add these reusable components to any model-driven or canvas app. Other than providing usability, the framework also provides powerful capabilities for advanced interactions. To facilitate the development of code components, the Microsoft Power Apps CLI tool enables component creation, easy debugging, built-in validation, and testing using a code editor of your choice.

PCF resolves some of the drawbacks we had for a long time with HTML web resources, such as the lack of flexibility and portability, by providing the ability to package a component with parameters. This means your component is abstracted from an environment and made into a truly reusable component. For example, say you want to show a weather forecast depending on the zip code from an entity record. If we had to do this using an HTML web resource, we would have to keep the forecast API information either hardcoded or in a configuration entity. To do the latter would mean an extra line of code. Also, because we want to read the zip code from the entity record, we would have to fetch the Xrm context using the window.parent method. This is simplified using PCF by using the parameters on the control configuration form. With the same example, you can capture the forecast API information as a component property and access the zip code data using the framework's context object, which provides a neat out-of-the-box way to access an attribute's data. We will be looking into this framework's context object further in later chapters.

Note

At the time of writing this book, PCF does not work on on-premises instances.

Now that you understand what PCF is and its history, let's look at who exactly it caters to.

Who is it focused on?

When Microsoft introduced the low-code-no-code platform, there were two terms used within the realm of business applications: citizen developer and professional developer. Citizen developers are not developers in the regular sense, and they may not know a coding language, but they are still involved in the development process through using low-code tools, such as canvas apps, Power Automate, and so on. These tools may not necessarily be straightforward and there is a bit of learning needed to use them. Professional developers are the ones who are more heavily involved in the development process and extend their platforms using various programming languages. These developers may create reusable components that can be utilized by citizen developers.

PCF is targeted more at professional developers, as along with knowledge of the framework, you also need basic knowledge of TypeScript, npm, and the web development process. This framework enables you to create code components that can be used by citizen developers on model-driven or canvas apps. Hence, now more than ever, we need a collaborative effort between citizen developers and professional developers to create holistic and usable systems.

If you are a professional developer with basic knowledge of JavaScript and Dataverse but you do not possess working knowledge of TypeScript or npm, do not worry, as this book will provide ample support for you to understand the basics needed to build a code component.

Note

The code components built using PCF are sometimes also referred to as custom controls.

Next, we will learn the difference between HTML web resources and code components and understand the reasoning behind keeping both HTML web resources and code components.

How are code components different from HTML web resources?

Now, you may wonder, do you need HTML web resources if you have code components? The answer is yes, we still need HTML web resources, and as of today, both have their own distinct ways that offer you full flexibility in customizing your system. For instance, code components can only be tied to a field or a dataset; so, if you have a requirement to add a custom piece of functionality to a dashboard that cannot be accomplished using iFrames or charts, you will still have to resort to HTML web resources.

The following table shows us some of the notable differences between HTML web resources and code components:

Table 1.1 – HTML web resources versus code components

Table 1.1 – HTML web resources versus code components

As you can see from the preceding table, HTML web resources help where PCF lacks and vice versa, providing you with full flexibility in customizing your application. Let's now look at the licensing needs.

Getting to know the licensing requirements

How a code component interacts with an external service determines the licensing scheme for the app that consumes the code component. The two license classifications are as follows:

  • When an app uses a code component that connects with an external service, it becomes premium, and end users need to have a Power Apps license.
  • If code components do not consume an external service, then the usage of such components in an app requires users to at least have a license for Office 365.

    Note

    A code component cannot be used in Dataverse for Teams.

Now that we understand the licensing requirements, let's go through the advantages of using PCF.

Exploring the advantages of PCF

When developing code components using PCF, it is important for you to know some of the advantages of the framework. They are as follows:

  • Access to a rich set of framework APIs that grant capabilities such as managing component life cycles and getting contextual data and metadata information.
  • Seamless server access through a web API, utility, and data formatting methods.
  • Access to device features, such as camera, location services, and microphone.
  • Provides a quickstart template that uses npm packages and webpack.
  • Optimized for performance.
  • Unlike HTML web resources, which get rendered as an iFrame, code components are rendered as part of the DOM, which provides an enhanced and seamless user experience.
  • Developers can utilize Power Apps capabilities to the fullest; for example, they can use the command bar on sub-grids.
  • Based on how code components are created, PCF can support both model-driven and canvas apps. We will be looking at the cases when a code component cannot support canvas apps in later chapters.

These are just some of the advantages of PCF. Let's now look at how to prepare your machine, which will help us develop the code components.