Azure Integration with Dynamics 365 CE/ CRM using Service Bus, Queue, Plugin Registration Tool and Azure Logic APP
Integrations is now an essential part of all business. Enterprise application integrations gives more flexible in handling Data in different systems at the same time. Microsoft Azure being the cloud technology provides a robust way of integration with other applications.
Dynamics 365 Can be integrated with Microsoft Azure using many methods as given below.
- Using Azure Service Bus and Queue
- Using Azure Functions using Web Hook concepts
- Web API using Client ID and ADAL concept
In this post we will see how we can integrate Dynamics 365 with Microsoft Azure Service Bus.
You can watch the video here otherwise scroll down to read all steps.
Step-1 : Create a Service Bus in Azure
Create a Service Bus in Microsoft Azure Portal. To Create a Service Bus click on Create a New Resource.
On the New screen choose Integration option and select Service Bus as given below.
The next screen will prompt you to provide the Subscription, Resource Group, namespace name, Location and pricing Tier.
Note :
- Choose your Azure subscription correctly.
- Select a Resource Group if already created or create new resource group.
- Give a Unique namespace for the Service bus.
- Choose a Location
- Choose Pricing Tier as per your choice, I use Basic Pricing Tier
See the below screenshot for more details.
After giving the details information click on Review + create. It will validate your details and allow to proceed further.
Now click on Create. Which will start creating the resource and it will display a “Deployment in progress” status screen.
After successful deployment it will display the message on the same screen and now click on the Go to Resource button.
The Go to resource will take you to the Service Bus Resource where we can do more.
Step-2 : Create a Queue inside the Service Bus
After the Service bus is created we need to add a Queue inside the Service Bus. Follow the steps below to add a Queue inside a Service Bus.
Being on the Service Bus Window click on Queue option from the Left side option panel.
In the new Queue creation window, provide the queue name and click on Create. This will create a Queue inside the service bus
Now we have to click the newly created Queue which will open the details about the queue.
In the details screen Navigate to Shared access policy option. Click +Add button to create a new SAS Policy. Give a name of the policy and click Manage option. After that click Create to finish.
Finally you should see the queue as below.
Now click on the Queue and from the right window copy the Primary Connection String option.
Paste the copied string in a notepad as we will use this connection string in later stage.
My Connection string looks like below.
Endpoint=sb://d365integrationsvc.servicebus.windows.net/;SharedAccessKeyName=d365integrationpolicy;SharedAccessKey=vMW/Jt0N+gsckXB43OK41Uc4zTCIF9Qi4szjAp9q5pg=;EntityPath=d365integrationsvcqueue
Till now we have completed the Queue creation. We will proceed to Plugin Registration tool for further integration.
Step-3 : Create Steps in Plugin Registration Tool for Integration
Open Plugin Registration tool from NuGet Manager or from Dynamics 365 SDK. Connect your Dynamics 365 Organization using credentials. Make sure you provide correct user name and passwords to login as sample given below.
After providing details click Login which will list all the plugins already installed in your current environment.
Now click on Register option from top and choose Register New Service Endpoint.
in the next screen choose “Lets Start with the Connection……”. Paste the connection string we have already copied from Queue property.
After providing the connection string click on Next. In the next screen we have to choose some more details. You have to provide the Queue Name and , Message Format as JSON and other details as below for sample.
Now after SAVE clicked, right click the Service Endpoint and Click on “Register New Step”
Choose Message as Create, Primary Entity as Account. The step will be Asynchronous, Server option enabled and stage will be PostOperation.
After providing the details click on “Register New Step“. Now we are ready to capture messages and entity contexts in an Azure Queue from Dynamics 365 whenever an account gets created.
Step – 4 : Create a Logic APP to read the Message and send to email
Create a Logic App with below steps to receive a message from a Queue. Then delay 20 seconds and send content in a email.
Step – 5 : Let’s Test the Integration
Open Dynamics 365 and open Sales Hub to create an account.
Create an account with name “MSFT ACCOUNT” and save the account.
Now we will go to Azure Queue and click on Refresh. You can see 1 message.
Now after some seconds you will receive an email with content.
Now the JSON is received in email. We can further think of what we can do with the JSON.
The JSON was given below
{
"BusinessUnitId":"09c60f89-ef36-eb11-a813-000d3a197120",
"CorrelationId":"bc17462d-ff57-4982-bda0-9b4d722e9252",
"Depth":1,
"InitiatingUserAzureActiveDirectoryObjectId":"00000000-0000-0000-0000-000000000000",
"InitiatingUserId":"2adc9ac0-2637-eb11-a813-000d3a197120",
"InputParameters":[
{
"key":"Target",
"value":{
"__type":"Entity:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Attributes":[
{
"key":"territorycode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"msdyn_travelchargetype",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":690970003
}
},
{
"key":"address2_shippingmethodcode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"isprivate",
"value":false
},
{
"key":"followemail",
"value":true
},
{
"key":"donotbulkemail",
"value":false
},
{
"key":"donotsendmm",
"value":false
},
{
"key":"createdon",
"value":"\/Date(1609746966000)\/"
},
{
"key":"statecode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":0
}
},
{
"key":"businesstypecode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"donotpostalmail",
"value":false
},
{
"key":"ownerid",
"value":{
"__type":"EntityReference:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Id":"2adc9ac0-2637-eb11-a813-000d3a197120",
"KeyAttributes":[
],
"LogicalName":"systemuser",
"Name":null,
"RowVersion":null
}
},
{
"key":"donotbulkpostalmail",
"value":false
},
{
"key":"name",
"value":"MSFT Account"
},
{
"key":"donotemail",
"value":false
},
{
"key":"address2_addresstypecode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"donotphone",
"value":false
},
{
"key":"transactioncurrencyid",
"value":{
"__type":"EntityReference:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Id":"5ab0fd8d-1337-eb11-a813-000d3a197120",
"KeyAttributes":[
],
"LogicalName":"transactioncurrency",
"Name":null,
"RowVersion":null
}
},
{
"key":"modifiedby",
"value":{
"__type":"EntityReference:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Id":"2adc9ac0-2637-eb11-a813-000d3a197120",
"KeyAttributes":[
],
"LogicalName":"systemuser",
"Name":null,
"RowVersion":null
}
},
{
"key":"statuscode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"modifiedonbehalfby",
"value":null
},
{
"key":"preferredcontactmethodcode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"owningbusinessunit",
"value":{
"__type":"EntityReference:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Id":"09c60f89-ef36-eb11-a813-000d3a197120",
"KeyAttributes":[
],
"LogicalName":"businessunit",
"Name":null,
"RowVersion":null
}
},
{
"key":"accountid",
"value":"e3c65949-624e-eb11-a813-000d3a9cc7fb"
},
{
"key":"createdby",
"value":{
"__type":"EntityReference:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Id":"2adc9ac0-2637-eb11-a813-000d3a197120",
"KeyAttributes":[
],
"LogicalName":"systemuser",
"Name":null,
"RowVersion":null
}
},
{
"key":"donotfax",
"value":false
},
{
"key":"merged",
"value":false
},
{
"key":"customersizecode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"marketingonly",
"value":false
},
{
"key":"accountratingcode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"shippingmethodcode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"msdyn_taxexempt",
"value":false
},
{
"key":"processid",
"value":"00000000-0000-0000-0000-000000000000"
},
{
"key":"creditonhold",
"value":false
},
{
"key":"modifiedon",
"value":"\/Date(1609746966000)\/"
},
{
"key":"participatesinworkflow",
"value":false
},
{
"key":"accountclassificationcode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"address2_freighttermscode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"msdyn_taxexemptnumber",
"value":null
},
{
"key":"msdyn_travelcharge",
"value":null
},
{
"key":"exchangerate",
"value":1.0000000000
},
{
"key":"msdyn_travelcharge_base",
"value":null
}
],
"EntityState":null,
"FormattedValues":[
{
"key":"territorycode",
"value":"Default Value"
},
{
"key":"msdyn_travelchargetype",
"value":"None"
},
{
"key":"address2_shippingmethodcode",
"value":"Default Value"
},
{
"key":"isprivate",
"value":"No"
},
{
"key":"followemail",
"value":"Allow"
},
{
"key":"donotbulkemail",
"value":"Allow"
},
{
"key":"donotsendmm",
"value":"Send"
},
{
"key":"createdon",
"value":"2021-01-04T13:26:06+05:30"
},
{
"key":"statecode",
"value":"Active"
},
{
"key":"businesstypecode",
"value":"Default Value"
},
{
"key":"donotpostalmail",
"value":"Allow"
},
{
"key":"donotbulkpostalmail",
"value":"No"
},
{
"key":"donotemail",
"value":"Allow"
},
{
"key":"address2_addresstypecode",
"value":"Default Value"
},
{
"key":"donotphone",
"value":"Allow"
},
{
"key":"statuscode",
"value":"Active"
},
{
"key":"preferredcontactmethodcode",
"value":"Any"
},
{
"key":"donotfax",
"value":"Allow"
},
{
"key":"merged",
"value":"No"
},
{
"key":"customersizecode",
"value":"Default Value"
},
{
"key":"marketingonly",
"value":"No"
},
{
"key":"accountratingcode",
"value":"Default Value"
},
{
"key":"shippingmethodcode",
"value":"Default Value"
},
{
"key":"msdyn_taxexempt",
"value":"No"
},
{
"key":"creditonhold",
"value":"No"
},
{
"key":"modifiedon",
"value":"2021-01-04T13:26:06+05:30"
},
{
"key":"participatesinworkflow",
"value":"No"
},
{
"key":"accountclassificationcode",
"value":"Default Value"
},
{
"key":"address2_freighttermscode",
"value":"Default Value"
}
],
"Id":"e3c65949-624e-eb11-a813-000d3a9cc7fb",
"KeyAttributes":[
],
"LogicalName":"account",
"RelatedEntities":[
],
"RowVersion":"4445751"
}
}
],
"IsExecutingOffline":false,
"IsInTransaction":false,
"IsOfflinePlayback":false,
"IsolationMode":1,
"MessageName":"Create",
"Mode":1,
"OperationCreatedOn":"\/Date(1609746966000+0000)\/",
"OperationId":"e8c65949-624e-eb11-a813-000d3a9cc7fb",
"OrganizationId":"33c988c6-0312-4484-8324-e26458e4c0b2",
"OrganizationName":"33c988c6031244848324e26458e4c0b2",
"OutputParameters":[
{
"key":"id",
"value":"e3c65949-624e-eb11-a813-000d3a9cc7fb"
}
],
"OwningExtension":{
"Id":"46558bf8-914a-eb11-a813-000d3a9cc7fb",
"KeyAttributes":[
],
"LogicalName":"sdkmessageprocessingstep",
"Name":null,
"RowVersion":null
},
"ParentContext":{
"BusinessUnitId":"09c60f89-ef36-eb11-a813-000d3a197120",
"CorrelationId":"bc17462d-ff57-4982-bda0-9b4d722e9252",
"Depth":1,
"InitiatingUserAzureActiveDirectoryObjectId":"00000000-0000-0000-0000-000000000000",
"InitiatingUserId":"2adc9ac0-2637-eb11-a813-000d3a197120",
"InputParameters":[
{
"key":"Target",
"value":{
"__type":"Entity:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Attributes":[
{
"key":"name",
"value":"MSFT Account"
},
{
"key":"msdyn_travelchargetype",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":690970003
}
},
{
"key":"msdyn_taxexempt",
"value":false
},
{
"key":"creditonhold",
"value":false
},
{
"key":"donotpostalmail",
"value":false
},
{
"key":"donotfax",
"value":false
},
{
"key":"donotphone",
"value":false
},
{
"key":"donotbulkemail",
"value":false
},
{
"key":"donotemail",
"value":false
},
{
"key":"preferredcontactmethodcode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"statuscode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"donotbulkpostalmail",
"value":false
},
{
"key":"processid",
"value":"00000000-0000-0000-0000-000000000000"
},
{
"key":"transactioncurrencyid",
"value":{
"__type":"EntityReference:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Id":"5ab0fd8d-1337-eb11-a813-000d3a197120",
"KeyAttributes":[
],
"LogicalName":"transactioncurrency",
"Name":null,
"RowVersion":null
}
},
{
"key":"ownerid",
"value":{
"__type":"EntityReference:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Id":"2adc9ac0-2637-eb11-a813-000d3a197120",
"KeyAttributes":[
],
"LogicalName":"systemuser",
"Name":null,
"RowVersion":null
}
},
{
"key":"accountclassificationcode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"customersizecode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"address2_freighttermscode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"followemail",
"value":true
},
{
"key":"shippingmethodcode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"participatesinworkflow",
"value":false
},
{
"key":"marketingonly",
"value":false
},
{
"key":"businesstypecode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"accountratingcode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"isprivate",
"value":false
},
{
"key":"merged",
"value":false
},
{
"key":"donotsendmm",
"value":false
},
{
"key":"address2_addresstypecode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"address2_shippingmethodcode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"territorycode",
"value":{
"__type":"OptionSetValue:http:\/\/schemas.microsoft.com\/xrm\/2011\/Contracts",
"Value":1
}
},
{
"key":"accountid",
"value":"e3c65949-624e-eb11-a813-000d3a9cc7fb"
}
],
"EntityState":null,
"FormattedValues":[
],
"Id":"e3c65949-624e-eb11-a813-000d3a9cc7fb",
"KeyAttributes":[
],
"LogicalName":"account",
"RelatedEntities":[
],
"RowVersion":null
}
},
{
"key":"SuppressDuplicateDetection",
"value":true
}
],
"IsExecutingOffline":false,
"IsInTransaction":false,
"IsOfflinePlayback":false,
"IsolationMode":1,
"MessageName":"Create",
"Mode":1,
"OperationCreatedOn":"\/Date(1609746966000+0000)\/",
"OperationId":"e8c65949-624e-eb11-a813-000d3a9cc7fb",
"OrganizationId":"33c988c6-0312-4484-8324-e26458e4c0b2",
"OrganizationName":"33c988c6031244848324e26458e4c0b2",
"OutputParameters":[
],
"OwningExtension":{
"Id":"46558bf8-914a-eb11-a813-000d3a9cc7fb",
"KeyAttributes":[
],
"LogicalName":"sdkmessageprocessingstep",
"Name":null,
"RowVersion":null
},
"ParentContext":null,
"PostEntityImages":[
],
"PreEntityImages":[
],
"PrimaryEntityId":"e3c65949-624e-eb11-a813-000d3a9cc7fb",
"PrimaryEntityName":"account",
"RequestId":"fbfec2b9-8b4f-4414-ace1-03e7aa470bff",
"SecondaryEntityName":"none",
"SharedVariables":[
{
"key":"IsAutoTransact",
"value":true
},
{
"key":"DefaultsAddedFlag",
"value":true
},
{
"key":"ChangedEntityTypes",
"value":[
{
"__type":"KeyValuePairOfstringstring:#System.Collections.Generic",
"key":"account",
"value":"Update"
}
]
}
],
"Stage":30,
"UserAzureActiveDirectoryObjectId":"00000000-0000-0000-0000-000000000000",
"UserId":"2adc9ac0-2637-eb11-a813-000d3a197120"
},
"PostEntityImages":[
{
"key":"AsynchronousStepPrimaryName",
"value":{
"Attributes":[
{
"key":"name",
"value":"MSFT Account"
},
{
"key":"accountid",
"value":"e3c65949-624e-eb11-a813-000d3a9cc7fb"
}
],
"EntityState":null,
"FormattedValues":[
],
"Id":"e3c65949-624e-eb11-a813-000d3a9cc7fb",
"KeyAttributes":[
],
"LogicalName":"account",
"RelatedEntities":[
],
"RowVersion":null
}
}
],
"PreEntityImages":[
],
"PrimaryEntityId":"e3c65949-624e-eb11-a813-000d3a9cc7fb",
"PrimaryEntityName":"account",
"RequestId":"fbfec2b9-8b4f-4414-ace1-03e7aa470bff",
"SecondaryEntityName":"none",
"SharedVariables":[
{
"key":"IsAutoTransact",
"value":true
},
{
"key":"DefaultsAddedFlag",
"value":true
}
],
"Stage":40,
"UserAzureActiveDirectoryObjectId":"00000000-0000-0000-0000-000000000000",
"UserId":"2adc9ac0-2637-eb11-a813-000d3a197120"
}c07dbdea-2182-4126-a38a-5ed2c33a5ee5