Skip to main content

Notifications

Leveraging NewRecord and OldRecord in Low-Code Plug-Ins for Dataverse

Inogic Profile Picture Inogic 24,094

Dataverse

Microsoft Dataverse offers low-code plug-ins to simplify the creation and management of event-driven workflows. Unlike traditional plug-ins that require custom .NET code and manual registration, low-code plug-ins are managed directly within Dataverse. These plug-ins use the Power Fx expression language to define their behaviour, enabling users to build complex workflows with minimal coding.

In this blog, we will see how we can use OldRecord and NewRecord in Low-Code Plugins in Dataverse. As the name describes, the “OldRecord” is used to store the attribute values which were present before saving the record and the “NewRecord” is used to store the attribute values which were present after saving the record.

Scenario: Prevent a user from decreasing the Credit Limit field value on an Account entity below its previous value

In many business systems, the Credit Limit field on an Account entity is a critical financial field that determines the maximum amount of credit a customer can use. For this example, we will ensure that the Credit Limit field cannot be decreased below its previous value. If a user tries to decrease the Credit Limit, the update will be blocked, and an error will be shown.

Let’s walk through how we can achieve this using a Low-Code Plugin in Dataverse.

Develop an automated plugin with the Dataverse Accelerator App

The automated plugin is triggered by events on Dataverse tables, such as create, update, and delete actions.

Low-Code Plug-Ins for Dataverse

Plugin Configuration:

  • Display Name: Provide a descriptive name for your plugin, such as “Prevent Credit Limit Decrease on Accounts.”
  • Table: Select the Accounts table, as we want this logic to apply to the Account
  • Run this plug-in rule when the row is: Choose Update from the list of data events. This will ensure the plugin runs when an Account is updated.
  • Expression: Enter the following Power Fx expression in the Expression editor:
If(

!IsBlank(OldRecord.'Credit Limit') && !IsBlank(NewRecord.'Credit Limit') && NewRecord.'Credit Limit' < OldRecord.'Credit Limit',

Trace("Credit Limit is being decreased from " & Text(OldRecord.'Credit Limit') & " to " & Text(NewRecord.'Credit Limit'));

Error("The Credit Limit cannot be lowered. Please enter a value greater than or equal to the previous limit.")

)
  • Advanced Options
  1. Solution: Select the solution where you want to save the plugin.
  2. When It Should Run: Choose whether this plugin should run during the Pre-operation or Post-operation For this scenario, it’s best to select Pre-operation so the check happens before the data is saved to the database.

As per our expression, if a user tries to update an Account and reduce the Credit Limit, the plugin will raise an error and prevent the update from being saved. If the credit limit is not decreased, the update will proceed normally.

Low-Code Plug-Ins for Dataverse

Low-Code Plug-Ins for Dataverse

To monitor the plugin’s behaviour, we can view the logs in the Plugin Monitoring section of Dataverse. This allows you to see which records triggered the plugin and whether the logic was applied successfully.

Low-Code Plug-Ins for Dataverse

In Plugin Monitoring, enabling all logs captures all trace messages, while exceptions only log errors. These settings can be adjusted in plugin registration and viewed under Plugin Monitoring in the Power Platform Admin Center.… Read More »

The post Leveraging NewRecord and OldRecord in Low-Code Plug-Ins for Dataverse first appeared on Microsoft Dynamics 365 CRM Tips and Tricks.


This was originally posted here.

Comments

*This post is locked for comments