This is a vast topic to cover in a blog. But I wanted to write from a bird-eye’s view of how this will pan out in an implementation where you perform a certain operation in Dynamics 365 CRM and an Azure Function is called to perform further operations.
This post is written keeping in mind fair knowledge of Azure Functions, Storage accounts and subscriptions in mind.
I’ll try to keep the article short, so stay with me! 🙂
Create a Function App in Azure
- Let’s say you have created a Function App in Azure already and want to connect to Dynamics 365 CRM. Click on the big + New Function button in the screenshot below
- Now, since I want to keep Visual Studio as my driver for coding and deployment, I’ll create a new Project in Visual Studio of type Azure Functions and click Next
- On the next page, I’ll give a relevant name and hit Create.
- Since we will be using Webhooks to connect to the Azure Function, the trigger chosen here is Http Trigger.Make sure you select Framework because Microsoft.Xrm.Sdk assemblies don’t work on .NET Code, but on .NETFramework only.And then you should take care of what your Storage Account and Authorization should be – Finally click Create once done.
- The Project will open with 1 .cs file, so make sure you name your plugin initially –
- It’ll take a while to create the Project. Once created, go to the Portal on Azure and click on the Get Publish Profile
It will be downloaded on the computer. Keep it so that you can import it on the Project in Visual Studio to use for Direct Publish.
- Now, right click and chose Publish to make your first push as is so that the Account Function gets pushed to Azure App.
- Then, click on Import and import the Publish Profile settings downloaded in step #5 above –
- Once imported, you’ll be taken here – simply Publish once.
- Once Publish is successful, check in the Azure App in Portal, the Function should appear.
Modifying code to read Webhook Call from Dynamics 365
- To keep it simple, I’m simply reading the context and then, you can flourish your App further to make it work as required.
So, I’m only reading the request into a String and logging it so that we can see it in the logs in the Azure Function app.
- You can use RemoteExecutionContext class to actually get all the contextual information into the Function app and then use it further. See below –
- Once ready with your code, Publish it.
Now, let’s Register the Webhook and call the app.
If you’re also looking for remote debugging, this is a great article-Remote Debugging Azure Functions V2 “The breakpoint will not currently be hit. No symbols have been loaded for this document”
Register a Webhook in Plugin Registration Tool
Coming to Dynamics 365 CRM side of things, you can register a Webhook that will trigger on Account Name update to fire off the AccountPlugin Function App created above –
- In Plugin Registration Tool, register a new Webhook
- Enter Webhook Details. Select Authentication type as WebhookKey –
- Now, to get the key, go to the Function App in portal, and look </> Get function URL link.
- Copy the same and paste in Notepad, separate the code part from the main URL
- Paste the URL part in Endpoint URL and key in the Value field. Click Save.
- Now, add a Step to the Webhook. For this example, I’ve chosen update of Account‘s Account Name field
And Register it.
- The purpose was to simply ready Dynamics 365 Account record upon modification of the Account Name
And save the record.
- In a minute or so, the Log will be generated (only the logs take a little longer to generate)
And thus, we are able to send data / or rather, call Azure Function and process Dynamics 365 CRM data using Webhooks.
Some other Azure related post you might like to look at – Use Azure App Passwords for MFA enabled D365 authentication from Console App
Hope this was helpful! Tried my best to keep it basic and short as possible. I’m sure you all will explore way beyond and develop awesome implementations!