How to write plugins in DataVerse using low code PowerFx functions.

Hello everyone and welcome to my blog. In today’s blog I will discuss about a very interesting feature that I came across – Low code plugins in DataVerse.

Before I go ahead and get started, please note that this is an experimental feature. You can learn about this in Microsoft Documentation.

Through my blog I share interesting tips and discuss on latest releases of Microsoft.NET technologies, Dynamics 365 and Power Platform, SharePoint and Client scripting libraries. Please subscribe to my blog to stay updated.

In this blog, I will share my first experiences of working with this feature.

Before you can get started with Low code plugins, you first need to install the DataVerse accelerator app in your environment. To do this, navigate to Microsoft App source and search for DataVerse accelerator app.

Click on Get it now. You will be redirected to a page where you will be required to select the environment where you want to install the app.

Wait for the app to get installed.

One the DataVerse Accelerator app is installed successfully, navigate to Power Apps Maker portal and ensure you are in the same environment where you have installed the accelerator. You should see the DataVerse Accelerator app in your Apps list.

Open the app. You will have the option to create Instant Plugins and Automated Plugins.

In today’s blog, I will focus on Automated plugins. Select New plugin option from Automate plugins. It takes me to the screen below from where I can create my first low code plugin.

The fist thing you should ensure is to select the right solution where you want your low code plugin to be created. The option to choose it is in the top right corner of the screen.

In the above illustration, I have chosen the ‘Sample solution‘ where the low code plugin should be created. More on that later.

The next steps are pretty self explanatory. You need to enter a name for the plugin, the table for which the plugin should be created and the whether it should execute on Create/ Update or Delete.

Screenshot below for illustration.

The next block you see on the screen is the area to define the formula. This is the engine of the Low code plugin where you logic reside. I am going to come to this in a moment.

Before that, check for ‘Advanced options’. You will find the option to execute the plugin in Pre or Post of an operation, just like the regular code based DataVerse plugins.

As you see in the below screenshot, I have chosen to execute the plugin in the Pre-operation stage.

Well, we are done with all our settings. Now comes the core part, the logic that we need to define in the formula area. Here I am going to perform few validations. The first validation to check if the field value entered is valid. The next one to check for duplicate records.

I have used the below code in my formula.

If(ThisRecord.'Milestone Status' = 'Milestone Status (Milestones)'.Cancelled 
&& IsBlank(ThisRecord.Reason), 
Error({Kind: ErrorKind.Validation, Message:"Reason is mandatory for status cancelled"}));

If(!IsBlank(LookUp([@Milestones], 'Milestone Title' = ThisRecord.'Milestone Title')),
Error({Kind: ErrorKind.Validation, Message:"Duplicate value for Milestone Title"}))

Beware of delegation when using PowerFx for Low code plugins. Observe the squiggly lines in code in the above screenshot. It’s a delegation warning since PowerFx Lookup support delegation for comparisons only on primary key. The duplicate detection will not yield accurate results for large datasets.

Observe the low code plugin in action in the below video. Wonderful isn’t it?

Now let’s take our learning a bit further. Remember at the start of creating the plugin, we chose the solution where the low code plugin should reside? Let’s open the same solution.

Surprisingly in the solution I don’t find the Low code plugin. Well it was not expected. I was thinking that choosing the solution shall automatically place the plugin inside the solution but it is not the case as it seems.

After much struggle, I could finally find a way to add the low code plugin. To add a low code plugin in your solution, choose Add Existing -> More -> Other – FxExpression. Screenshot below for reference.

Select the plugin you want to add.

Finally I could add it to my solution.

That’s great. But here is the catch!

Although I could add the Low code plugin in the solution, export it and then import it in the target environment, the plugin won’t execute in the target environment. This is a limitation with Low code Automate plugins only. Low code instant plugins are part of ALM.

I am pretty sure Microsoft is going to get around this limitation once the feature is GA.

Now before I sign off, lets try a post-update scenario. In this scenario I tried to create new tasks and associate it with Milestone once a Milestone is created. This will work for any scenario where you are trying to create child records post creation of parent record inside a Low code plugin.

Below is the code to do the same.

Patch(
    [@Tasks], 
    Collect([@Tasks], {Subject:"Task 1 for Milestone"}),
    { Regarding: ThisRecord}
);

Observe the usage of the @ operator to explicitly access a table. This is mandatory. Also not to forget that not all PowerFx constructs are supported in Low Code plugins.

Strangely, this code won’t work in Post operation of update. The same in post-update shall generate an error – “Cannot find primary record id“. As per my understanding, the Patch function in post-update is expecting existing records only and not able to create new record. Not sure it is an intended behavior or product bug but I will wait for further updates from Microsoft regarding this feature.

The low code plugin currently support this construct of Patch function only.

PatchDataSourceBaseRecordChangeRecord1 [, ChangeRecord2, … ])

There are quite a few limitations as of the time of writing this blog. But as I keep on working with this and get to know more, I will keep on updating this blog with latest information.

For the list of known limitations, please visit this link. Personally I would recommend to use this with caution . As of the time of writing this blog, this is experimental feature and rightly so but at the same time it’s a great promise of the things to come in the future. Imagine migrating many of the complex code you write in DataVerse plugins today to the low code framework especially when it becomes fully ALM supported with support of entire PowerFx suite.

Hope this helped. For similar interesting topics on Microsoft.NET and Power platform, please subscribe to my blog.

Debajit Dutta
Business Solutions MVP


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading