Using New Bulk Operation Messages in the Plugin

By | September 11, 2023

Make your developers’ lives easy with yet another feature added to Microsoft Dynamics where they can perform operations using new plug-in messages that have been Introduced for bulk operations as below. Let’s dig into this preview feature!

  • CreateMultiple: Creates multiple records of the same type of entity in a single request.

Example:

Using-New-Bulk-Operation-Messages-in-Plugin

  • UpdateMultiple: Updates multiple records of the same type of entity in a single request.

Example:

Using-New-Bulk-Operation-Messages-in-Plugin

  • UpsertMultiple: This operation is yet to be introduced so this is not supported as of now.
  • DeleteMultiple: This operation can only be performed for elastic tables where you Delete multiple records of the same type with a single request.

Example:

Using-New-Bulk-Operation-Messages-in-Plugin

You can register plug-in on these new messages as seen below:

Using-New-Bulk-Operation-Messages-in-Plugin

Using-New-Bulk-Operation-Messages-in-Plugin

Note: The filtering attribute for this message is not available right now but it might be introduced in the future as this is in preview. But the final additions waited to be seen.

Microsoft Power Platform

Though these bulk operation messages are getting introduced, we can continue using Create, Update, and Delete methods for plugins and there is no need to migrate the existing ones whereas we can write plugins separately for these bulk operations mentioned above.

Since these are bulk operations performed at once when we write a plugin on these messages it is obvious that there will be differences between the parameters that we will be receiving in the Plugin Context or the entity images we will be using with these bulk operation messages.

So below are the things to be noticed while using these new plugin messages:

1. Change in the ExecutionContext Object

We need to use the IPluginExecutionContext4 interface instead of IPluginExecutionContext, to get these target and entity image collections in the plugin context as explained below.

Using-New-Bulk-Operation-Messages-in-Plugin

Once we initialize the context with the IPluginExecutionContext4 interface we can then move ahead.

Note: If you are unable to locate IPluginExecutionContext4 while developing a plugin try to remove the references and Install NuGet Package “Microsoft.CrmSdk.CoreAssemblies” with the latest version.

2. Target of Entity

Since we will be performing multiple create/update operations in one go when the plugin gets triggered you will receive multiple targets instead of one. For single create/update we receive Target as the input parameter whereas in CreateMultiple/UpdateMultiple we receive Targets as an input parameter.

For Example: If I am writing a plugin on CreateMultiple request then we will receive Multiple target records on which we can apply business logic based on the requirement

context.InputParameters.Contains(“Targets”)

Earlier we used to check for single Target entity records as the plugin gets triggered on single record creation, now we will get multiple targets in the context.

3. Target EntityCollection

As we will receive multiple targets in the plugin context, we will receive this in an Entity collection so we need to validate that the target is an entity collection when we write a plugin to Create/update multiple requests.

Using-New-Bulk-Operation-Messages-in-Plugin

Once we receive the entity collection we can loop through the collection and apply the business logic for the plugin.

4. PreEntityImagesCollection and PostEntityImagesCollection Images

These entity images are only available when you use the IPluginExecutionContext4 Interface, which provides the PreEntityImagesCollection and PostEntityImagesCollection properties. These arrays provide access to the entity images in an EntityCollection.

To get these entity image collections we need to loop through the target entity collection and get the entity image collection of each record as seen below

Using-New-Bulk-Operation-Messages-in-Plugin

But there are some limitations too as listed below:

  • Since the plugin has a limitation on execution and it should not exceed a 2 2-minute timeline, it is not advisable to perform bulk operations within the plugin with an extremely large amount of data.
  • If you are performing Bulk operations from any other tools then you can write a plugin to Create/Update multiple messages, you should consider reducing the number of records that are passed in the Targets parameter. In this way, the plugin can perform the business logic without any timeout issues.
  • Also, we found that as this plugin executes in a single transaction, if 1 record execution fails then it fails all other records too which are used in the bulk operation message request.

Other limitations can be found here https://learn.microsoft.com/en-us/power-apps/developer/data-platform/bulk-operations?tabs=sdk#limitations Also some known issues can be found here as well https://learn.microsoft.com/en-us/power-apps/developer/data-platform/bulk-operations?tabs=sdk#known-issues

Conclusion

Provides you the best performance when you run operations on multiple rows of a Microsoft Dataverse table, use one of the above bulk operation messages to reduce time when you want to perform custom business logic on these bulk operations.