Skip to content

Power Fx plugins explained for the citizen developer

Power Fx plugins were released in Spring 2023 as an experimental feature. Plugins have been created in Dataverse for a long time, via writing traditional C# code. Now they can be made with Power Fx, which is a citizen developer friendly way. Yet these terms may not be familiar to all potential makers with access to Power Platform tools.

Plugins are practically pieces of code that are executed on the server side, in the Dataverse cloud (not in the end user’s browser, meaning client side). They can start automatically when a row is added, edited or deleted in Dataverse (Automated plugin). The plugin can also be started independently (Instant plugin). Plugins can inject custom business logic to complement the standard events that the platform offers for Dataverse (including Dynamics 365 app logic).

Power Fx, on the other hand, is a low-code programming language based on the syntax familiar from Microsoft Excel formulas. Canvas Power Apps have been using it since the start, and today it is being implemented across the Power Platform tools to make it easy for power users to express business logic without having to learn a traditional programming language.

Since the Dataverse low-code plugins feature is now scheduled to be generally available in December 2023, it’s a great time for all app makers to try creating their first plugins. In this post we will cover:

  • Where do we create Power Fx based plugins and what are the prerequisites.
  • Example scenario for creating an automatically triggered plugin for validating data on forms.
  • Why instant plugins that need manual triggering are also useful for app makers.
  • How combining Power Fx plugins with in-app notifications allows us to monitor asynchronously executed Power Automate cloud flow runs.

Dataverse Accelerator

Creating Power Fx plugins requires the Dataverse Accelerator solution. Microsoft has started installing this solution automatically to all new environments as of October 2023. If it’s not present in your environment yet, installing it from the AppSource is not particularly difficult. After installation, you will find the Dataverse Accelerator App in your environment:

Today, the application allows the environment maker or system administrator to create these Power Fx plugins. In the future there may be more features launched that leverage the same Dataverse Accelerator UI.

But what the heck can you do with these plugins in practice? Let’s get to know them with a few examples.

Automatically starting plugin (Automated)

Automated Power Fx plugins are triggered whenever something happens on a Dataverse table row (create, update, delete). We’ll look at how these are useful for example scenarios of 1) form data validation and 2) creating entries in a log table.

Form data validation

In our example Order App, we create orders using a very simple form on a model-driven Power App. One of the fields on the form is the client’s business ID.

Before saving the data in the form, we want to make sure that the business ID is in the correct format.

This could be done with JavaScript, but instead, we create an automatically starting plugin that starts when the order is created.

During creation, a regular expression is used to check whether the business identifier is in the form 1234567-1 (Finnish format). If it is not, an error message is displayed to the user.

If(
   !IsMatch(ThisRecord.cra3a_businessid, "^\d{7}-\d{1}$"), 
   Error({ Kind: ErrorKind.Validation , Message: "Not valid Business Id"})
   )

This is done before actually saving the data (Pre-operation). In practice, we prevent the form from being saved if the business id is not in the correct format.

Like this:

Unlike JavaScript, the plugin prevents saving data everywhere. On all forms, but also in canvas Power Apps. However, the error message is not as clear:

Creating a row into log table

We can do (almost) everything in the plugin that Power Fx is capable of through its growing number of formulas. Below, a new item is created in a custom Dataverse log table every time a new order is created:

In a similar way, we could, for example:

  • Fill some information in the form using conditional logic, based on form fields already filled or referencing information from another related record.
  • Create additional order lines and attach them to this line (e.g. a standard order line, such as handling or postage costs).
  • When deleting a row, use your own logic to delete other rows as well (cascading delete).

Manually started plugin (Instant)

An instant Power Fx plugin is like a function that can be called from different places. You can pass parameters to it (input parameters) and it can return values ​​to its caller (output parameters).

Let’s look at a couple of examples of this as well. First we’ll do a simple manipulation of a text value (string). Finally, we will leverage a plugin to notify the user of a model-driven Power App when something happens in the background – which in our case is a cloud flow run completion.

String truncation

Let’s make a plugin that truncates the string when it is too long (more than 12 characters). Give the plugin a name and description:

After this, the input and output parameters are defined:

  • Title (string, input parameter)
  • ShortTitle (string, output parameter)

The code is simple:

{ShortTitle: If(Len(Title)>12, Left(Title,10) &"..", Title)}

How do we trigger this plugin from the canvas Power Apps? First the “Environment” table needs to be added as a data source into the application. The environment’s existing plugins can be retrieved from there.

A text input control is added to the application. Our plugin is called when the control value changes (OnChange). The return value (ShortTitle) is stored in the variable (locShortText).

UpdateContext(
{locShortText:Environment.cra3a_GetFirst10Character({Title:Self.Text}).ShortTitle}
)

A label control is added to the screen, where the value of the variable is displayed.

It works!

Why don’t we add the plugin call directly to the label’s text property? Because we can’t. The plugin can only be used with an event (OnSelect, OnUpdate, OnChange, etc.).

However, this example should really be implemented as a canvas component. Plugins run in Dataverse, not in the browser. This means a request is sent to the Dataverse server every time the user edits the value of the text field:

On the other hand, I can use the same plugin in Power Automate cloud flows. With the “Perform an Unbound action” step, we’re able to call the plugin as an action:

The end result is of course the same:

In-app Notifications

This is a surprisingly useful scenario in real-world applications. Let’s imagine a situation where a flow is started from a model-driven app form:

The execution of the flow takes a long time (several minutes) and we want to notify the user once the flow run has completed. But the flow is executed asynchronously, meaning in the background. The application will not by default know anything about the end result of the flow run.

Here’s where the beauty of Power Fx plugins working on both the app side and the automation side become very clear. Let’s first create a plugin that sends a notification to the user:

The plugin will receive these input parameters:

  • The Azure ID of the user receiving the notification (UserAADObjectId)
  • Did the execution of Flow succeed (succeed)
  • From which record the flow was started (rowItemGui)

The notification is sent with the following Power Fx command:

XSendAppNotification(
    "Long running operation is now done", 
    LookUp(Users, 'Azure AD Object ID'= GUID(UserAADObjectId)),
    If(succeed,
       "All good, ready to go!", 
       "Background flow failed. Please try again."
      ),
    [
 	XCreateSidePaneActionForEntity(
     	  "View Item",
 	  rowItemGuid,
 	  "Test Table Item",
 	  "cra3a_testtableplugins",
 	  LookUp(
            'test table plugins',
            'test table plugins'=GUID(rowItemGuid)
           ).'test table plugins'
     	 )
    ]
)

In-app notifications are disabled by default. Let’s turn them on from the model-driven app settings.

Now, at the end of the flow, we can send a notification to the user who started it.

Like this:

Summary

Power Fx plugins are in the process of becoming generally available. This means you could start using them in production environments for your apps and flows.

These low-code plugins are a great addition to the Power Platform maker’s toolbox. In addition to cloud flows, classic workflowscustom actions, etc.

They are also a great example of how Power Fx is spreading across the Power Platform. So, it’s super useful for both citizen and professional developers to learn to write Power Fx.

Automated PluginsCanvas Power AppsDataverseDataverse AcceleratorInstant PluginsModel-driven appsPluginsPower AppsPower Fx

Leave a Reply

Your email address will not be published. Required fields are marked *