Business Logic

What are the options to implement server-side business logic in Dataverse?  In this post I’ll discuss when to use a cloud flow vs a plugin.

Dataverse has some basic built in business logic capability.  For example, mathematical calculations can be executed by using a rollup or calculated column and business rules can set or clear column values

If you have a need for more complex business logic, then you will need much more than what can be implemented ‘out of the box’.  A cloud flow or a plugin will be required.  There are no hard and fast rules on which to choose, but read on and I’ll cover the important issues to consider when making your choice

dataverse

Why Have Business Logic In Dataverse?

Executing logic within Dataverse instead of within a Canvas App has particular advantages:

  • Canvas Apps are not designed to run complex code or calculations. Power FX is becoming a rich and flexible language so often the business logic can be coded, but it can run slow.  Executing business logic on Dataverse is quicker
  • Because the logic is running in the cloud, its execution is invisible to the user. If the output is required to be displayed to the user, this can be done once the code has run
  • The code executes irrespective of the client device that triggered it, so if you have a Canvas App and Power Pages using the same table for example, then having business logic in Dataverse means the code only needs to be written once
  • Because Dataverse has in-built security, access to sensitive information can be better protected

Cloud Flow or Plugin?

When it comes to implementing business logic in Dataverse there are 2 primary options:

  • Cloud Flows
  • Plugins

I say primary options because as with all complex ecosystems like Dataverse, the Power Platform and Dynamics 365, there are often several ways to achieve a similar result.  I’ll touch on these other options through this article but the primary consideration will be cloud flow vs plugin  

As a guide, use a cloud flow where possible.  Cloud flows are easier to create, implement and maintain because they are low-code.  Power Automate has a large and diverse portfolio of steps available to create a cloud flow and using one or multiple steps in combination could well meet your requirements.  Adding the configuration parameter to a step is preferable to coding from ‘scratch’ as is the case with a plugin and it will not require input from a C# developer

In particular, if the logic requires integration with another platform, always look at a cloud flow first because Power Automate has access to hundreds of pre-built connectors.  If there isn’t a pre-built connector that meets your needs then a custom connector can usually be created and used in the flow.  It will be more complex to integrate with an external platform using a plugin

However, cloud flows have their limitations and it may not be possible to create the exact complex logic you require just using low-code.  A plugin is a better solution for example, when a complex mathematical algorithm is required.  A plugin is a .NET assembly uploaded to Dataverse and registered to run on a specific event.  A practical example of how this would be useful is the logic for a credit rating that is executed when a new record is created.  Under these circumstances, the best solution would be a plugin containing a credit rating function making use of the required C# operators to handle the mathematical complexity

A Hybrid Solution

It is perfectly do-able to use a combination of both a cloud flow (eg for integration with another platform) and to invoke a plugin (to execute the more complex logic)

This is achieved by calling an action from the cloud flow which in turn passes the required parameters and invokes the plugin.  Alternatively an action can be invoked by a plugin which in turn initiates a cloud flow

Using either of these approaches can give the best of both options

Externally Hosted Logic

Depending on the user case, the business logic might not need to reside on Dataverse.  Going back to the example of a credit rating calculator, this may be a hosted business service (such as an Azure Function) or outsourced to a 3rd party credit rating agency

When a credit application is made and a record created on Dataverse, a cloud flow with a custom connector could pass the relevant parameters to the business service or 3rd party.  The credit rating results are calculated and the results returned back in to the cloud flow and stored on Dataverse

Note that Dataverse could also send data to an external platform using a plugin.  Alternatively a Dataverse webhook could be used.  A webhook is a HTTP connector that connects to Web APIs and services and supports synchronous and asynchronous communications.  However, for the reasons discussed earlier, a cloud flow should be your first choice

The creation of the credit rating service as an Azure Function would require the services of a pro developer as Azure Functions are usually created in C#, JavaScript or Typescript

Additional Considerations

Bear in mind that Power Automate cloud flows do not run synchronously in the way that classic workflows do, but they are near real time.  If the logic is required to be absolutely synchronous then consider using a classic workflow.  The section below contains a link summarising the differences between a cloud flow and a classic workflow.  Plugins can be synchronous or asyncronous

Plugins have a 2-minute timeout which may be a limitation.  Cloud flows have timeout after 30 days which give greater flexibility, for example in the case of a credit rating application, the cloud flow could accommodate human intervention on borderline cases

Plugins give greater flexibility over execution performance, for example, control over threading. Plugins can also be triggered by a wider range of events than a flow, though in typical usage the tiggers available to a flow are perfectly adequate

Additional Material

Leave a Comment

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

Scroll to Top