top of page

Challenge 022 | Dataverse Accelerator

Last month I aimed at making Dataverse look less scary for Citizen Developers. This month we will continue on that journey. As of October 1st, every new environment will have the Dataverse Accelerator installed automatically. It brings creating plug-ins to the world of Citizen Developers, so a perfect topic for this month's challenge.

Challenge Objectives

🎯 Learn about Dataverse plug-ins

🎯 Know how to use Dataverse Accelerator

🎯 Understand the difference between server-side and client-side logic

Introduction

What is Dataverse Accelerator?

Microsoft is clearly pushing experimental features in the form of Accelerators and Kits for us to try out and give feedback on. The good things of these products will come in product. Good examples of this are the start of the ALM Accelerator, which led to the pipelines in managed environments and the modern controls which are clearly inspired by the Creator Kit. So we can be quite sure that the Dataverse Accelerator will lead to some in-product functionality in the near future. The naming of this Accelerator is ambiguous compared to the others mentioned, but Dataverse Accelerator focuses on low-code plug-ins. (Maybe Plug-in Accelerator would be an idea??..)

Creating plug-ins traditionally meant writing some C# code, assemble a plug-in, and registering it to your Dataverse instance. This clearly requires developer skills. The Dataverse Accelerator brings creating plug-ins to the Low-Code / Citizen Development realm. Every initiative that brings capabilities over from the pro-code to low-code makes me excited. But before we dive into creating these low-code plug-ins, we should learn a bit about what these plug-ins actually are, what they do, and when these can be of value to us.

Implement logic

A plug-in is a form of server-side logic. In Challenge 017 we learned the difference between client and server side. In a nutshell, client side logic is the logic you use in your application, and server side logic is what runs on the server / in the cloud. It is good practice to put the logic on the server side, whenever possible. The reason for this is that this way any application built on this Dataverse instance uses this logic. With client side logic, each application should have the logic built in the app. You can imagine that updating and making sure every application applies the same logic is much harder this way. Besides that, it has also much better performance.

For Dataverse, there are several ways to implement logic:

  • Business rules

  • JavaScript

  • Workflows

  • Power Automate flows

  • Plug-ins

Business rules

Client-side. Typically used to adjust a particular form field based on another field. Think of making a field required, hidden, set the default value, etc. These come in handy mostly in Model-Driven Apps. Business rules are built using a drag-and-drop interface, so perfect for low-code developers.

JavaScript

Client-side. Similar to Business rules, it is used to apply form logic for Model-Driven Apps, but extends beyond the capabilities of Business rules. The name itself already tells us that this option is much more on the pro-code side than the low-code side. That being said, Dani Kahil created the JavaScript Cheatsheet that makes using this much more accessible. Sweet.

Workflows

Server-side. Workflows are no longer recommended by Microsoft and are therefor not discussed. Only mentioned for completeness.

Power Automate flows

Server-side. The one we know best, probably. It is quite versatile as it allows for connecting to many other data sources with all the available connectors. The interface is also pretty good for low-code developers, both for creating the flow as debugging with the flow history (and triggering the flow again with the same input). As good of an option this is, there are some limitations. The performance of cloud flows might me too limited for you.

Plug-ins

Server-side. The main advantage of plug-ins is that they can handle more advanced tasks. Traditionally it would mean you will need a developer to make and maintain plug-ins, but the Dataverse Accelerator makes it much more accessible to low-code developers.

Low-code plug-ins

Dataverse Accelerator is a low-code plug-in editor. We have the option to create an instant or an automated plug-in. An automated plug-in is based on an action in Dataverse, just like we have the Dataverse triggers in Power Automate. Technically speaking, every action in an application results in a call to your Dataverse instance (like an action in Power Automate). these messages are sent through a standard execution pipeline, or stages. A plug-in adds logic to one of those stages. The available stages are:

  • PreValidation

  • PreOperation

  • MainOperation

  • PostOperation

The low-code plug-ins only support PreOperation and PostOperation stages for now. These are also the most commonly used stages, so that's fine. The naming of these stages are quite self-explanatory. The PreOperation stage should contain logic to determine is an action should be executed. The PostOperation logic will contain actions that must be executed after an action. The first is more like extra layer of checks, the second is similar to a Power Automate flow with a trigger When an item is created/updated/deleted.

The good thing is that low-code plug-ins can use connectors to integrate other data sources using connection references directly in Power Fx. Also, recently was announced that low-code plug-ins are fully ALM supported. I think these two reasons are why it now is pre-installed to every environment.

I think that's enough theory for now.

Install the solution

Existing environments

Dataverse Accelerator can be installed from AppSource. This means that you don't have to import the solution manually. The Dynamics 365 apps page in the Power Platform Admin Center allows you to browse through the AppSource solutions and deploy them to a particular environment. Just search for Dataverse Accelerator and install it to the environment of your choice. You could also go to the Dynamics 365 apps at the environment level, but not all environments have this listed (e.g. Developer environment).

The AppSource way also makes updating much easier. The environments with Dynamics 365 apps listed under resources in the admin center show all installed apps. If an update is available, you can simply click the update button.

You can make it even easier by setting up auto-updates in your environment. You can select a publisher and all the solutions from that publisher will be auto-updated. Fot the Dataverse Accelerator that would be Microsoft Corp - Power CAT. pretty sweet.

New environments

For new environments you have to do nothing. The deployment of Dataverse Accelerator is part of the environment provisioning process and will stay up-to-date automatically. Nice!

Create low-code plug-in

Make sure that you have created a new solution before you proceed. This will make it much more easy for you to understand what is actually happening. I called my solution Challenge 022. Also make sure you opened the Dataverse Accelerator App that is installed to your environment.

Instant plug-in

An instant plug-in is similar to an instant cloud flow, in a way that you can manually run the plug-in, or call it through an API. At least it is not triggered by an action in Dataverse. Let's create a plug-in that can calculate the diagonal of a right triangle using the Pythagorean theorem.

  • In the Dataverse Accelerator app, click Instant plug-in

  • Name your plug-in Pythagoras - diagonalf

  • Add two input parameters named a and b. Both should be integers.

  • Add an output parameter named c. Again an integer.

  • In the Expression section you can enter the Power Fx function. The only thing that is different here is that output parameters must be references inside of curly brackets. This results in the snippet below.

{c: Sqrt(a^2 + b^2)}
Output parameters must be referenced inside of curly brackets
  • Expand the Advanced options

  • Put the plug-in in the Solution we created earlier, Challenge 022

  • Give it a description

  • Set the scope to global. The entity option should be used when you want some entity data as an input, which is not the case for our plug-in.

Your plug-in should look like the image below.

Save your plug-in and go to the test section. Give a 3 as an input and for b enter 4. this should result in an output of 5. Run it. The output should look like the image below.

Now have a look at your solution. Note that Dataverse Accelerator created various resources with the input parameters as Custom API Request Parameters, the output parameter as a Custom API Response Property, the FxExpression is probably where the Power Fx expression is stored and the Custom API is our endpoint we can talk to. This looks pretty low-code to me!

Invoke instant plug-in from Power Automate

It might not make sense for now, but we can call the action we just created from within Power Automate. It might not make sense to you right now as we discussed the difference between Power Automate an plug-ins. But I think this is actually a great example. We can define an action once, and reuse that logic across multiple Power Platform resources. We can put it in app, but also in flows. This way we can store the logic once, centrally. Perhaps the Pythagorean theorem isn't the best example, but I hope you get my point. Let's make a flow.

  • Add an instant Power Automate flow to solution Challenge 022

  • Add two input variables. Again a and b, both numbers

  • Add the Dataverse action Perform an unbound action

  • Search of Pythagoras, as that is what we named it

  • Note that the input parameters from the plug-in are shown. Map them to the input variables of the flow

  • Add a compose action and enter the c value from the Dynamic Content panel

Your flow should look like the image below.

Invoke instant plug-in from Power Apps

Now that we know where to find these plug-ins, it should be easy to add it to a canvas app.

  • Add a canvas app to solution Challenge 022 named Instant plug-in

  • Add two text input controls. Name them txtParameterA/B make sure the format is set to number and add the hint text enter the a/b value

  • Add a button. Rename it to btnCalculateC and set the text property to Calculate c.

  • Add the Dataverse table Environment as a data source

  • Make sure the button will create a global variable named varPluginOutput. That would be Set(varPluginOutput. Add a comma and enter Environment. This allows you to browse through the available plug-in actions available. If you enter a dot (.) after Environment, you can type Pythagoras and you action will pop-up. here are also the input properties shown. It should be easy to add. Just to be sure I added the function in a snippet below.

  • Add a text label that will show the varPluginOutput value.

Set(varPluginOutput, Environment.new_Pythagorasdiagonal({a: txtParameterA.Text, b: txtParameterB.Text}))

The function should now work. Note that we added some client-side logic in the canvas app by setting the text input to format number. This way we can only enter numbers, which is a form of logic. Also disabling the button when one of the input field doesn't contain any value is client-side logic, which will improve the user experience. You can go even further by updating the varPluginOutput when a value in an input control is changed. That way you will never mistake an output based on input parameters.

I hope these suggestions are helpful to understand the difference between client-side and server-side logic. Understanding the difference will help you move more logic server-side and make you a better developer.

Automated plug-in

A common validation made client-side is to check if an end date is later than the starting date. In Dataverse you will probably use Business rules for this, but I want to keep it simple for this challenge. As we know by now, an automated plug-in is based on a Dataverse event. So we first will need a table in our solution. I named mine Challenge, and added two date columns named Start Date and End Date. Based on this information you could know that we will be making a PreOperation plug-in and not a PostOperation plug-in.

  • Create an Automated plug-in

  • Name it Start Date lt End Date

  • Select the Challenge table we created earlier

  • Make sure Created and Updated are checked. Deleted should be unchecked

  • Set the expression to the snippet below

  • Set the stage to PreOperation

  • Add the plug-in to solution Challenge 022

If(ThisRecord.'Start Date' > ThisRecord.'End Date', Error({Kind: ErrorKind.Validation, Message: "Start Date must be before End Date"}))

Save it and it should be ready to go. You could create a Power Automate flow or canvas app to test it, but we've done that already. The nice thing about the modern UI for Dataverse is that we can quickly read and create records. If we show the column we need and add a record, you can see that an error message is shown. Because we throw an error, the MainOperation and PostOperation stages are cancelled.

Add Connectors to plug-in

In this last section I will show how you can use Power Platform connectors in your plug-in. Let's say that when we create a new challenge, we want to know what temperature it was at that moment. It's a lack of creativity, but it's just for you to know how this is done. For each connector it work the same.

  • Go to connections in your environment

  • Create a new connection for the MSN Weather connector

  • Add a connection reference to your solution named MSN Weather Challenge 022

  • Add a column to your table named Temperature and make it a float

  • Create a new automated plug-in named Add Temperature

  • Enter the Challenge table and only check the Created checkbox

  • Prepare your patch function so that we only need to add the temperature from the connection reference, It Should look like the snippet below.

Patch(Challenges,ThisRecord, {Temperature: })
  • In the top-right corner, select the connector icon. You will see all the connection references available. Select the MSN Weather connector. You will see all the possible actions. Select Get current weather. You can then press copy.


  • You can then just paste it in your Power Fx function and feed it the expected properties. You can find the properties in the connector documentation. The Learn button will guide you there. IntelliSense in the Expression editor also shows the names of the required properties.

Anti-climax alert, I did not got the connector part working in my environment. This blogpost mentions that the support for this will be there starting November 2023. That might be the issue. The reason I kept it in this Challenge is that the way you can add them will not change, so maybe by the time you are doing it, it works as a charm.

Additional Information

There are more example plug-ins available. The are some limitations of Power Fx functions low-code plug-ins. There is a great YouTube video that shows how to combine SQL stored procedures with low-code plug-ins.

Key Takeaways

👉🏻 Plug-ins allow you to add server-side logic to your Dataverse solutions

👉🏻 Dataverse Accelerator makes creating plug-ins fairly easy (No C#, yay)

👉🏻 Try to make logic server-side whenever possible

댓글


bottom of page