Integrating Dynamics 365 with Azure Functions – Part 2

By | June 11, 2018

Integrating D365 with Azure Functions

Introduction:

In our recent blog, We saw how to create an Azure function and now that we have our Azure function ready and hosted, let’s look at invoking the function through a workflow. At this point, we will execute the function through an HTTP request instead of registering the function as a Webhook.

Let us modify the code from our previous blog to connect to a SQL database and return a record. We will then use the data returned from SQL to create a record in CRM.

Since VS Code does not provide intellisense, we will write the code in VS and then copy it to VS Code – Is there a better way to do this?

In VS, we have the following function ready

We will copy this function to VS Code and save. You will find the following errors reported for missing references.

Integrating D365 with Azure Functions

To reference assemblies in .csx we need to add the following lines in the run.csx

Integrating D365 with Azure Functions

Create a bin folder and copy Newtonsoft dll there so that it is referenced correctly here.

Next, replace the code to use full qualified type names “System.Data.DataRow”

Let us call this function from the main function and pass the data received in the name querystring to the function to look up the record from SQL

Once it compiles fine, upload the code to Azure and test it.

Execution from Postman will now show the following result

Integrating D365 with Azure Functions

Let us now call this from a workflow assembly

The following code snippet would invoke the azure function using HTTP POST request.

Note: We are accepting Function URL and secret as a workflow parameter

Register the workflow assembly and execute the workflow. It would read from Azure SQL and create a contact in CRM

In the next step, we would register the Azure function as a Webhook.

Conclusion:

Using the simple steps above the user can register the workflow assembly and execute the workflow. In our next blog will see how to register the Azure function as a webhook and register steps for messages that you would like the custom logic to be executed for.

Copy System and Custom Entities in Dynamics CRM

Leave a Reply