How to bypass Power Automate flow execution during DataVerse operations

Hello everyone and welcome to my blog. In today’s blog I will discuss a very interesting topic – how to bypass Power Automate flows during DataVerse operations.

When a row is added, modified or deleted in DataVerse, we can add Power Automate flows for these triggers. However if you are performing a batch job using SDK in a plugin or a batch job using CrmServiceClient, Power automate flow(s) registered for these operation(s) will trigger for each record.

Through my blog I share interesting tips and discuss on latest releases of Microsoft.NET technologies, Dynamics 365 and Power Platform, SharePoint and Client scripting libraries. Please subscribe to my blog to stay updated.

In scenarios like this, there is sometimes a requirement to bypass custom code. You custom code can be plugins, DataVerse classic workflows or even Power Automate flows. To bypass synchronous custom code, we can use the BypassCustomPluginExecution. Click here to know more about this.

However the same property won’t work to suppress Power automate flows. For Power automate flows, we have the SuppressCallbackRegistrationExpanderJob property. When this property is set to true for an operation, any Power automate flow registered for that operation will not trigger.

Let’s validate this with a simple example. I have Power automate flow registered on create of a contact in DataVerse.

I have set the Scope to Organization so that the Power automate flow trigger for all contacts created in the organization.

Below is a sample code to create a contact record using CrmServiceClient.

 static void CreateRecord(CrmServiceClient client)
      {
         try
         {
            Entity entity = new Entity("contact");
            entity.Attributes["firstname"] = "SDK Contact";
            entity.Attributes["lastname"] = "Flag not set";
            entity.Attributes["emailaddress1"] = "sdkcontact1@gmail.com";

            CreateRequest createRequest = new CreateRequest()
            {
               Target = entity
            };
            

           client.Execute(createRequest);
         }
         catch(FaultException<OrganizationServiceFault> fault)
         {
            string errorMessage = fault.Detail.Message;
         }
         catch (Exception ex)
         {
            string errorMessage = ex.Message;
         }
      }

When I run the code, quite expectedly the the Power automate flow execute.

To prevent this flow from executing, I tweak the previous code to set the SuppressCallbackRegistrationExpanderJob property. Check for the sample code below.

static void CreateRecord(CrmServiceClient client)
      {
         try
         {
            Entity entity = new Entity("contact");
            entity.Attributes["firstname"] = "SDK Contact";
            entity.Attributes["lastname"] = "Bypass flag set";
            entity.Attributes["emailaddress1"] = "sdkcontact2@gmail.com";

            CreateRequest createRequest = new CreateRequest()
            {
               Target = entity
            };
            createRequest.Parameters.Add("SuppressCallbackRegistrationExpanderJob", true);


            client.Execute(createRequest);
         }
         catch(FaultException<OrganizationServiceFault> fault)
         {
            string errorMessage = fault.Detail.Message;
         }
         catch (Exception ex)
         {
            string errorMessage = ex.Message;
         }
      }

Check for the code highlighted in the bold. I set the parameter value to true.

When the above code is executed, the contact record is created in DataVerse. But if you now check the flow runs, you will find that the flow is not triggered.

You should be careful when you set this parameter. The flow owner won’t be notified that the flow has been bypassed. Also there is no special privilege required to execute this logic.

SuppressCallbackRegistrationExpanderJob property work inside plugins as well. So if you want to suppress a Power automate flow during a DataVerse operation from plugins, set this parameter value to true.

Hope this helped. For similar interesting topics on Microsoft.NET and Power platform, you can subscribe to my blog.

Debajit Dutta
Business Solutions MVP