In the previous post, we saw how we can register webhook for the azure durable function. In this post we’ll see how we can use custom global action to invoke webhook and pass plugin execution context to the webhook.

Let’s go to D365 instance and create a global action as shown below:

We have passed 3 input parameters as mentioned below:
ServiceCeaseDate : Date value to be updated on accommodation payment records(Expected Refund Due Date)
TargetEntity : Entity name passed as string
TargetID : GUID of contact record to be passed as string

Then let’s write code to invoke webhook. Since webhook details are stored in serviceendpoint entity we are passing schema name of this entity and plugin execution context on Line 17(highlighted below) as shown:

 public class ExecuteActionUpdateAccommodationPayments : PluginBase
        override public void Execute(ILocalPluginContext localContext)
            IServiceEndpointNotificationService cloudService = (IServiceEndpointNotificationService)localContext.CloudService;

            if (cloudService == null) return;

            var dataContext = new CrmServiceContext(localContext.OrganizationService);
            var webHookIDSetting = (from s in dataContext.dxc_systemsettingSet
                                    where s.dxc_name == "WebHookID"
                                      && s.dxc_Group == "Other"
                                    select s.dxc_Value).FirstOrDefault();

            if (string.IsNullOrWhiteSpace(webHookIDSetting)) return;

            string response = cloudService.Execute(new EntityReference("serviceendpoint", new Guid(webHookIDSetting)), localContext.PluginExecutionContext);

We are getting webhook GUID from system setting(custom entity) as shown on line 9-13(highlighted above) instead of using hardcoded GUID as shown below:

Then let’s deploy the code using plugin registration tool and add a step for action as shown below:

In the next post, we’ll see how we can execute custom global action using JS based on a particular business requirement.

Hope it helps !!