Dynamics 365 – Bypass Custom Business Logic

If you are a developer working with Dataverse, you may have encountered situations where you need to perform bulk data operations without triggering the custom business logic that is applied by plug-ins, workflows or Power Automate flows. For example, you may want to import a large number of records from an external source, or update some fields across multiple entities, or delete some obsolete data. In these scenarios, you may want to bypass the custom business logic to speed up the process and avoid performance issues.

Fortunately, Dataverse provides some optional parameters that you can use to bypass custom business logic for specific requests. In this blog post, I will explain what these parameters are, how to use them, and what are the benefits and risks of doing so.

BypassCustomPluginExecution

The first optional parameter is BypassCustomPluginExecution, which allows you to bypass custom synchronous logic. This includes synchronous plug-ins and real-time workflows that are registered for the events that occur because of your requests.

To use this parameter, you need to meet two requirements:

  • You must send the requests using the BypassCustomPluginExecution optional parameter.
  • The user sending the requests must have the prvBypassCustomPlugins privilege. By default, only users with the system administrator security role have this privilege.

When you use this parameter, all custom synchronous logic is disabled except for:

  • Plug-ins that are part of the core Dataverse system or part of a solution where Microsoft is the publisher.
  • Workflows included in a solution where Microsoft is the publisher.

These exceptions are necessary to ensure the core behaviors and functionality of Dataverse and Microsoft solutions are not compromised.You can use this parameter with either the SDK for .NET or the Web API.

How to Bypass Custom Plugin Execution in Dynamics 365 by Using C#

static void DemonstrateBypassCustomPluginExecution(IOrganizationService service)
{
Entity account = new("account");
account["name"] = "Sample Account";
CreateRequest request = new()
{
Target = account
};
request.Parameters.Add("BypassCustomPluginExecution", true);
service.Execute(request);
}

The benefit of using this parameter is that it can reduce the time and resources needed to complete bulk data operations by skipping the custom synchronous logic that may not be relevant or necessary for your scenario. However, the risk is that you may bypass some important logic that ensures data consistency or functionality for your organization or other solutions. Therefore, you should check with your system administrator and other solution providers before using this option.

Adding the prvBypassCustomPlugins privilege to another role

Because the prvBypassCustomPlugins privilege isn’t available in the UI to set for different security roles, if you need to grant this privilege to another security role you must use the API. For example, you may want to grant this privilege to a user with the system customizer security role.

The prvBypassCustomPlugins privilege has the ID 148a9eaf-d0c4-4196-9852-c3a38e35f6a1 in every organization.

static void AddprvBypassCustomPluginsToRole(IOrganizationService service, Guid roleId)
{
var request = new AddPrivilegesRoleRequest
{
RoleId = roleId,
Privileges = new[]{
new RolePrivilege{
PrivilegeId = new Guid("148a9eaf-d0c4-4196-9852-c3a38e35f6a1"),
Depth = PrivilegeDepth.Global
}
}
};
service.Execute(request);
}

How to Bypass Power Automate Flow Execution in Dynamics 365 by Using C#

The second optional parameter is SuppressCallbackRegistrationExpanderJob, which allows you to bypass Power Automate flows that respond to Dataverse events using the When a row is added, modified or deleted or When an action is performed triggers.

To use this parameter, you don’t need any special privilege. However, you should only use it if you experience performance issues due to a large number of system jobs created by these flows.

When you use this parameter, Dataverse does not create system jobs to execute these flows for your requests. This can improve the performance of Dataverse by reducing the load on the system. However, the flow owners will not receive any notification that their logic was bypassed. This means that they may miss some important events or actions that their flows are supposed to handle. You can also use this parameter with either the SDK for .NET or the Web API.

static void DemonstrateSuppressCallbackRegistrationExpanderJob(IOrganizationService service)
{
Entity account = new("account");
account["name"] = "Sample Account";
CreateRequest request = new()
{
Target = account
};
request.Parameters.Add("SuppressCallbackRegistrationExpanderJob", true);
service.Execute(request);
}

The benefit of using this parameter is that it can mitigate performance issues caused by large numbers of system jobs created by Power Automate flows. However, the risk is that you may bypass some critical logic that depends on these flows. Therefore, you should communicate with the flow owners and consider some mitigation strategies before using this option.

Leave a comment