How to Bypass Custom Synchronous and Asynchronous Business Logic in Dynamics 365

By | November 11, 2024

Bypass Custom Synchronous and Asynchronous Business Logic in Dynamics 365

In Microsoft Dynamics 365, plugins and workflows are powerful tools for automating business processes and logic. These automations can be synchronous (sync) or asynchronous (async) and are typically designed to trigger based on specific business events. However, there are scenarios where you might want to bypass these custom business logics. For such cases, Microsoft provides a mechanism called BypassBusinessLogicExecution.

BypassBusinessLogicExecution is a feature that allows you to temporarily bypass the execution of custom plugins, workflows, and other business logic for specific operations. This can be particularly useful in situations where you need to perform bulk updates, data imports, or other administrative tasks where the usual business logic does not need to be applied.

We were importing the Bulk Data and we have our own business logic. When a contact record gets created, the note should also get created.

Now when I import the bulk contact records, I don’t want to create any notes. Sure, I can find and disable all the plugins and workflows related to the creation of contact records. But that would be a hectic task to perform. Here I can use Bypass all Custom Business Logics in my environment.

Note: When you send requests that bypass custom business logic, all custom plug-ins and workflows are disabled except plugins and workflows where Microsoft is the publisher.

BypassBusinessLogicExecution is an optional parameter that targets the custom business logic applied for your organisation.

There are two values for this parameter that we can use to define what type of logic we want to bypass:

  1. CustomSync — Bypass only synchronous custom logic.
  2. CustomAsync — Bypass only asynchronous custom logic, excluding Power Automate Flows.
  3. CustomSync,CustomAsync — Bypass both synchronous and asynchronous custom logic, excluding Power Automate Flows.

There is a prerequisite we need to follow before using this:

The user initiating the requests must hold the prvBypassCustomBusinessLogic privilege, which is, by default, granted only to users with the system administrator security role.

prvBypassCustomBusinessLogic user privilege can only be given by code there is no user     interface to give this user role.

Create a request for Synchronous Logics.

Entity Contact = new("contact");

contact ["firstname"] = "John";

contact ["lastname"] = "Doe";

CreateRequest request = new()    {        Target = account    };

request.Parameters.Add("BypassBusinessLogicExecution", "CustomSync ");

service.Execute(request);

Create Request for Asynchronous Logic.

Entity Contact = new("contact");

contact ["firstname"] = "John";

contact ["lastname"] = "Doe";

CreateRequest request = new()    {        Target = account    };

request.Parameters.Add("BypassBusinessLogicExecution", "CustomAsync ");

service.Execute(request);

Or we can bypass Both at the same time.

Entity Contact = new("contact");

contact ["firstname"] = "John";

contact ["lastname"] = "Doe";

CreateRequest request = new()    {        Target = account    };

request.Parameters.Add("BypassBusinessLogicExecution", "CustomSync, CustomAsync ");

service.Execute(request);

Let’s See how can we assign this prvBypassCustomBusinessLogic privilege to a security role via code:

The ID for the prvBypassCustomBusinessLogic privilege is

0ea552b0-a491-4470-9a1b-82068deccf66”.

var request = new AddPrivilegesRoleRequest

{

RoleId = yourSecurityRoleId,

Privileges = new[]{

new RolePrivilege{

PrivilegeId = new Guid("0ea552b0-a491-4470-9a1b-82068deccf66"),

Depth = PrivilegeDepth.Global

}

}

};

service.Execute(request);

Bypassing Specific Plugins

You can bypass specific plugins by passing the step IDs:

request.Parameters.Add(“BypassBusinessLogicExecutionStepIds“, “45e0c603-0d0b-466e-a286-d7fc1cda8361,d5370603-e4b9-4b92-b765-5966492a4fd7”);

You can find the step IDs in the Plugin Registration Tool.

By default, you can add up to 3 step IDs when bypassing plugins. This limit can be adjusted through the `BypassBusinessLogicExecutionStepIdsLimit` setting in the Organization Settings.

Although BypassCustomPluginExecution is still supported, it’s recommended to use BypassBusinessLogicExecution with the CustomSync value for similar results.

Conclusion

BypassBusinessLogicExecution in Dynamics 365 allows admins to streamline bulk data imports and updates by temporarily bypassing custom business logic. This feature saves time and simplifies data management, making it an invaluable tool for efficient operations.

Business Process Checklist