CRM Crate

Bypass plug-ins & workflows during data operations in Power Apps

In this blogpost, we will learn to bypass or skip the plug-ins and workflows while performing data operation in Power Apps or Dynamics 365 CE . Before we begin, ensure you subscribe to CRM Crate to remain informed about the latest developments in the Power Platform field.

Bypass plug-ins & workflows during data operations in Power Apps

Plug-ins are custom business logic that you can integrate into Dynamics 365 CE to extend its capabilities. Think of them as event handlers that you can attach to certain events within the system. For instance, you might want to perform a specific action every time a record is created, updated, or deleted. Plug-ins allow you to do this.

Key Points about Plug-ins:

  1. Event-Driven: Plug-ins are executed in response to specific events. These events could be related to entities like lead creation, contact updates, or opportunity closures.
  2. Server-Side: They run on the server side, which means they execute as part of the server processing the request.
  3. Extensibility: You can write plug-ins in .NET using C#, which gives you a lot of flexibility to perform complex operations.
  4. Performance Considerations: Since plug-ins run on the server, poorly written plug-ins can impact system performance. Therefore, it’s essential to ensure they are optimized and efficient.

Workflows, on the other hand, are more about automating business processes with and without writing code. They allow users to create rules that automate tasks such as sending emails, updating records, or creating tasks based on certain conditions.

Key Points about Workflows:

  1. Declarative: Workflows are designed using a visual interface where you can define steps and conditions.
  2. Background or Real-Time: Workflows can run in the background or in real-time. Background workflows are asynchronous and do not block the user, while real-time workflows execute immediately and can halt the current operation if necessary.
  3. User-Friendly: They are designed to be configured by power users or administrators without the need for deep technical knowledge.
  4. Integration with Business Logic: Workflows can be used to enforce business rules consistently across the organization.

Understanding when and how to use plug-ins and workflows in Dynamics 365 CE can significantly enhance your system’s functionality and efficiency. Plug-ins offer powerful customization options for complex logic, while workflows provide a user-friendly way to automate business processes. By combining these tools effectively, you can tailor Dynamics 365 to meet your organization’s unique needs seamlessly.


Why do we need to bypass plug-ins or workflows in Power Apps / Dynamics 365 CE?

Sometimes, you need to do data tasks without applying specific business logic. This usually happens during bulk data operations, like creating, updating, or deleting many records at once. If you’re developing a client application, you have the option to include specific additional parameters in your requests. Dataverse offers developers of client applications a range of optional parameters and request header values. These parameters help manage two types of customized business logic, as outlined below:

Synchronous Logic

To speed up bulk data operations, skip the synchronous logic if you know the data already meets organizational requirements or if you have another way to handle this logic. By bypassing custom synchronous logic, each operation can finish faster, reducing the overall time needed for the bulk operation.

Power Automate Flows

When numerous system jobs for flows create a backlog in Dataverse, it can affect performance. To avoid this issue, you can prevent the flows from triggering during bulk operations.

Thus, we can use an optional parameter in Dataverse CRUD operation header to bypass plug-ins and workflows in Power Apps.


How to bypass synchronous logic such as Plug-ins or Workflows?

To bypass custom synchronous logic, you can use the BypassCustomPluginExecution or BypassBusinessLogicExecution optional parameter. If you don’t use this parameter, you’ll need to find and disable the custom plug-ins that contain the synchronous logic while performing data operation. However, this means the logic will be disabled for all users while those plug-ins are turned off. You’ll also need to ensure you disable the correct plug-ins and remember to re-enable them later.

By using this optional parameter, you can selectively disable custom synchronous plug-ins for specific requests made by an application configured with this option.

Below are the two pre-requisites for bypassing synchronous business logic.

  1. You need to send the requests using the BypassCustomPluginExecution or BypassBusinessLogicExecution optional parameter.
  2. The user making these requests must have the prvBypassCustomPlugins privilege. By default, only users with the system administrator security role have this privilege.

The BypassCustomPluginExecution parameter is designed to target the custom synchronous business logic implemented for your organization. When requests bypass this custom business logic, all synchronous plug-ins and real-time workflows are disabled, except for the plug-ins & workflows that are part of core Microsoft Dataverse solution (Where Microsoft is the publisher).

The BypassBusinessLogicExecution optional parameter functions much like the BypassCustomPluginExecution optional parameter. However, it allows you to decide whether to bypass synchronous logic, asynchronous logic, or both. You can pass the additional parameters along with BypassBusinessLogicExecution as given below.

CustomSync

Skip solely synchronous custom logic. The computation time needed for synchronous operations adds to the overall time for each data task. Employ this choice to trim down the time needed for bulk operations.

CustomAsync

Skip asynchronous custom logic alone, except for Power Automate Flows. Dataverse implements asynchronous logic post-operation completion. When numerous operations activate asynchronous logic, Dataverse demands more resources for custom logic processing, potentially impacting performance. Opt for this choice to steer clear of performance hitches arising from a high volume of operations triggering asynchronous logic.

CustomSync,CustomAsync

Exclude Power Automate Flows and skip both synchronous and asynchronous custom logic.

Using BypassCustomPluginExecution option in SDK for .NET

There are two methods for utilizing this optional parameter with the SDK for .NET.

Method 1 (BypassCustomPluginExecution Optional Parameter):

Here’s an example where we set the optional parameter BypassCustomPluginExecution while creating a new lead record using the CreateRequest class.

static void CRMCrate_BypassCustomPluginExecution(IOrganizationService service)
{
Entity lead= new("lead");
lead["fullname"] = "Prashant Tirlotkar";

CreateRequest request = new()
{
Target = lead
};
request.Parameters.Add("BypassCustomPluginExecution", true);
service.Execute(request);
}

If the invoking or impersonating user possesses the prvBypassCustomPlugins privilege, you can employ this approach for data operations initiated in your plug-ins.

Method 2 (CrmServiceClient.BypassPluginExecution property):

Here’s an example that demonstrates setting the CrmServiceClient.BypassPluginExecution Property while creating a new lead record.

var service = new CrmServiceClient(connectionString);  

service.BypassPluginExecution = true;

var lead = new Entity("lead");
lead["fullname"] = "Prashant Tirlotkar";

service.Create(lead);

As this setting is applied at the service level, it stays active for all requests made through the service until it’s explicitly set to false. It is important to note that this property is available in Dataverse.Client.Extensions.CRUDExtentions methods and not in Dataverse.Client.ServiceClient.


Using BypassBusinessLogicExecution option in SDK for .NET

Here’s an example that demonstrates how to configure the BypassBusinessLogicExecution optional parameter for both synchronous and asynchronous custom logic when creating a new lead record using the SDK for .NET CreateRequest class.

static void CRMCrate_BypassBusinessLogicExecution(IOrganizationService service)
{
    Entity lead= new("lead");
    lead["fullname"] = "Prashant Tirlotkar";

    CreateRequest request = new()
    {
        Target = lead
    };
    request.Parameters.Add("BypassBusinessLogicExecution", "CustomSync,CustomAsync");
    service.Execute(request);
}

How to add the prvBypassCustomPlugins privilege to a security role?

Since you can’t access the prvBypassCustomPlugins privilege directly through the Model-Driven App UI to assign it to various security roles, you’ll have to utilize the API if you want to grant this privilege to another role. For instance, you might want to give this privilege to a user who holds the system customizer security role. Use the below SDK for .NET code for adding this privilege in your security role.

static void AddPrivilege(IOrganizationService service, Guid securityRoleId)
{
var request = new AddPrivilegesRoleRequest
{
RoleId = securityRoleId,
Privileges = new[]{
new RolePrivilege{
PrivilegeId = new Guid("148a9eaf-d0c4-4196-9852-c3a38e35f6a1"), // This is the GUID for prvBypassCustomPlugins privilege.
Depth = PrivilegeDepth.Global
}
}
};
service.Execute(request);
}

3 2 votes
Article Rating
Subscribe
Notify of
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
error: CRM Crate Security Engine - Disabled Right Click & Selection!

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.