Thursday, January 19, 2017

Dynamics 365 and Logic Apps–Part 2

In the first part of the blog, I had created a Logic App that serves as a callable endpoint to create a record in CRM. In this blog, we will look at adding some exception handling to the same app. Please read the first part Using Logic Apps to create records in Dynamics 365 - Part 1 to understand this part.

Current Solution

The process for the current solution in depicted in the following diagram


If the Create a new record is successful the Response action will return the customer else the Logic app will through an error message.

What will happen when CRM throws an error

For this blog, I have created a synchronous workflow that will throw an error message if the Last Name is not provided in the request.

Error 1 (ResponseTimeOut)

I am sending the following request without the last name.
  "customer": {  
   "firstName": "MSCRMShop",  
   "streetAddress": "21 2nd Street",  
   "city": "New York"  
The Logic App returned the following error message.
  "error": {  
   "code": "ResponseTimeout",  
   "message": "The server did not received a timely response from the upstream server. Request tracking id '08587170410911854011608943569'."  


The reason behind the timeout error is that there is timeout limit of 90 seconds for a single http request in Logic Apps. The other question is that why CRM would take so long to return the error message. The reason is that CRM is not taking that long to throw the error message. It is the default retry policy of the Logic Apps that will try 5 times before throwing the error message.

For verification, open the Logic App in Azure portal and look at the failed run. The action will display the message shown in the following screen shot.


The App run is showing that the execution duration is 1.92 minutes. The error captured in Create a new record is the actual error thrown by CRM
Now log on to CRM and check the execution history of the workflow. It will display that it has been executed 5 times.



The solution in this scenario is to set Retry Policy to None for the action Create a new record. Switch to code view of the app and add the retry policy section as shown in the following screen shot.


Error 2 (NoResponse)

After fixing the Error 1, call the Logic App again by passing same body as in Error 1. This time the app will return the following error.
  "error": {  
   "code": "NoResponse",  
   "message": "The server did not received a response from an upstream server. Request tracking id '08587169819578381630235279815'."  


The reason is that there is no response defined in our current solution to handle the error. The only response defined in the Logic App is to return the customer Id on successful creation of the record in CRM. Every action in Logic Apps have a section named “runAfter” which defined when this action will be executed.



The solution in this scenario is to add another Response action that will be executed after the failed execution of Create a new record action.
  1. Add a new Response action to the app and set the properties as shown in the screen shot below.


    Status Code is set to output of Create a new Record, Headers section contains the content-type and Body is set to body of Output of Create a new Record.
  2. At this stage Response 2 will be fired on successful execution of Response action.
  3. Switch to the code view of the app. Scroll down to Response 2 definition.
  4. Change the runAfter section as shown below.

  5. Save the app.
  6. Switch back to designer mode and if there is no error in the app. It will look like the following screen.

  7. Test the Logic App again without passing the last name in the request body. This time Logic app will return the following message.


This solution will only capture the errors thrown by CRM (Create_a_new_record action). If the error occurs before the call that won’t be captured by the solution.

More Resources

Check the following resources for advanced error handling information.

Monday, January 9, 2017

Using Logic Apps to create records in Dynamics 365 - Part 1

According to Microsoft documentation, Logic Apps is a service to simplify and implement scalable integration and workflows in the cloud. As a CRM professional I was aware of Microsoft Flow but not of Logic Apps. Microsoft Flow is actually built on Logic App Most of the features and API connections are the same.

The major difference is that Microsoft Flow is targeted for business users whereas Logic Apps is targeted towards IT professionals and developers. Logic Apps can have some additional connections like BizTalk APIs. The other major difference is that Microsoft Flow workflows are created in production but Logic Apps provides the DevOps and security assurance.

The following link details the comparisons between Microsoft Flow and Logic Apps
For this Blog I am building a Logic App that will act as endpoints to create records in Dynamics 365. The good thing is that we don’t need to write code to create the endpoints.

Create a Logic App

  1. Logon to the Microsoft Azure Portal.
  2. Create a new Logic App by Navigating to New>>Web +Mobile>>Logic App as shown in the screen shot below.

  3. Enter the app name and other information as required and click Create. (I generally checked “Pin to Dashboard” to open the app straight from the dashboard)

  4. Open the newly created app.

  5. Click on Edit to open the designer.

  6. Select Request from the list of the managed APIs as shown in the screen shot.

  7. Enter the JSON schema for the request. I have created a customer object with first name, last name, street address and city.

  8. Click Save. It will populate the URL field of the request. This URL will be used as endpoints to call the Logic App.
  9. Click New step and choose Add an action.

  10. Select Dynamics 365 – Create a new record from the managed APIs list.

  11. Choose the Organisation Name, choose the Contacts as the entity name and map the first name, last name, street address and city with the JSON schema added in step 7.

  12. Click New step and choose Add an action as shown in the screen shot below.

  13. Select Response from the list.
  14. Enter the following information as shown in the screen shot below
    • Status Code of 200 (Which represents successful call).
    • Enter the “content-type” in the Headers section.
    • Enter the JSON in the body section. I am returning the contactid of the newly created contact.2017-01-08_17-52-28
  15. Save the app and test it.

Testing the Logic App

For testing we need to call Logic App using URL created for Request step 8 of Create a Logic App.


For this blog, I am not creating a new application to call the endpoints(Logic App). I am using PostMan to create and send the request. Here are the steps.

  1. Open the PostMan application.

  2. Enter the URL copied from the Request.
  3. Enter the Headers as shown in the screen shot below. The endpoints are expecting JSON.

  4. Enter the Body and Click Send. The  Logic App will return the customer id as shown in the screen shot below.

  5. Open the CRM and check the contact is created.
  6. If there is an error, go to Azure portal and look the app summary and troubleshoot the error.


That is it . You got your Logic App as callable endpoints.


Tuesday, December 13, 2016

Adding Icons and Tooltips to grid columns in Dynamics 365

I was going through the “What’s New” section of the Dynamics 365 SDK and found out that you can now add icons and tool tips to the grid view columns.
Microsoft has added the 2 imageproviderwebresource and imageproviderfunctionname to the layout xml of the <cell> attribute of the saved query. These fields can be used to attach a web resource and JavaScript function that will display the icon and the tooltip.
For this blog, I am displaying red, yellow and green light bulbs based on the priority of the case.
Here are the steps:

Create 3 Icon web resources

  • Find 3 icon/image files for red, green and yellow color. I am using PNG files of size 16x16 pixel for this example.
  • Create a new web resource of type “PNG Format” as shown in the screen shot below.

  • Repeat the above step for green and yellow icons.

Create a JavaScript web resource

Create a JavaScript web resource with the following function. It is the same function that is used in SDK sample. The function takes the 2 parameters rawdata and userLCID. The userLCID can be used to display the tip in different languages. Check the SDK example for details. In this example I am not using userLCID as only default English language is installed in my CRM.
 //display icon and tooltio for the grid column  
 function displayIconTooltip(rowData, userLCID) {  
   var str = JSON.parse(rowData);  
   var coldata = str.prioritycode_Value;  
   var imgName = "";  
   var tooltip = "";  
   switch (coldata) {  
     case 1:  
       imgName = "new_/images/red.png";  
       tooltip = "High Priority Case";  
     case 2:  
       imgName = "new_/images/yellow.png";  
       tooltip = "Noraml Priority Case";  
     case 3:  
       imgName = "new_/images/green.png";  
       tooltip = "Low Priority Case";  
       imgName = "";  
       tooltip = "";  
   var resultarray = [imgName, tooltip];  
   return resultarray;  

Attaching JavaScript web resource to the view column

  • Open the view for which you would like to display the icons and tooltips. For this example, I am using “My Active Cases”.
  • Select the column Priority and click on “Change Properties”

  • Specify the JavaScript web resource and function name.



Publish all the customizations completed in the above step. Navigate to “My Active cases” and check the results. You will notice different color icons based on the priority of the case.


Sunday, November 27, 2016

Enhancements to Client side Notifications in Dynamics 365

Microsoft introduced client side notifications in CRM2013. Dynamics 365 has introduced enhancements to this functionality.
A new method addNotification has been added to to the client side API. This method can:
  1. Display a error or recommendation notification. In the earlier version the only option available was error notifications.
  2. It also allows you to specify and execute actions based on the notification. The new method not only display the notification, it also display 2 buttons:
    • “Apply” to execute the action
    • “Dismiss” to close the notification


The following sample code will display recommendation notification if there are numbers in the “name” of the account. If the user clicks on “Apply” button, it will remove the numbers from the name and clear the notification. If the user clicks on “Dismiss” button, the notification will be closed.
 function addNotification() {  
   //get the name control  
   var myControl = Xrm.Page.getControl('name');  
   //get the name attribute  
   var accountName ='name');  
   //get the value name attribute  
   var accountNameValue = accountName.getValue();  
   //if the account name is null then return  
   if (accountName.getValue() == null) {  
   //regular expression to find numbers  
   var r = /\d+/;  
   var s = accountNameValue.match(r);  
   //if match the display the message  
   if (s != null) {  
     var actionCollection = {  
       message: 'Remove the numbers from the name?',  
       actions: null  
     actionCollection.actions = [function () {  
       //remove the numbers  
       accountName.setValue(accountNameValue.replace(/[0-9]/g, ''));  
       messages: ['Number/s in the account name'],  
       notificationLevel: 'RECOMMENDATION',  
       uniqueId: 'my_unique_id',  
       actions: [actionCollection]  



When the user clicks “Apply”, the system removes the number 7 from the name.

This functionality will be very useful in number of scenarios, for e.g. validating a field and recommending a value, moving the focus to specific tab or field, validating the field value on the parent entity, and opening the parent form to update the fields etc..

Wednesday, November 16, 2016

Interesting integration scenarios for Dynamics 365

The release of Dynamics 365, along with the general availability of Microsoft Flow, Power Apps with CDM(Common Data Model), and the vast range of Azure services have opened up a whole new world of integrated solutions.

I will go through the following 3 scenarios to show case the integration possibilities for Dynamics 365. This blog will only discuss the architecture of the solution, not the actual implementation. The aim of this blog is highlight the solution possibilities using Dynamics 365 and Azure cloud.

Integration of Dynamic 365 with Power apps

Technologies used

  • Dynamics CRM 365
  • Microsoft Flow
  • Common Data Model (Part of Power Apps)
  • Power Apps
  • PowerBI

Solution Overview

The following depicts the solution architecture of Dynamics 365 and PowerApps.
  1. A record is created/updated in Dynamics 365 which triggers Microsoft Flow workflows to create/Update the record in CDM.
  2. The PowerApps’s mobile app connected to CDM presents the data to end users.
  3. The end users read,create or update the data on the mobile app.
  4. The changes are saved in CDM that triggers the Microsoft Flow workflows to create/update the data in Dynamics 365.
The data in CDM can be used by PoweBI for analytics. You can also add the data into CDM from different sources to get the consolidated view of the data.

Integration of Dynamics 365 with Microsoft Bot framework

Technologies used

  • Dynamics CRM 365
  • Microsoft Flow
  • SharePoint Online
  • Azure Storage
  • Azure SQL database
  • Azure Search
  • Cognitive Services
  • Microsoft Bot Framework
  • Skype.

Solution Overview

I am very impressed with this solution. This scenarios depicts the business process of an insurance company where users have applied for the policy online. The business process workflow creates profiles in Dynamics 365 and stores the customer application in SharePoint Online.

A Microsoft Flow workflow will push structured data into the Azure SQL Database and the unstructured data into Azure Blobs.

Azure Search crawls the data at regular intervals and keeps it current for querying.

End users interact with the Bot application using Skype. The Bot application processes the user requests without any human interaction using cognitive services.

The whole solution is taken from the following blog: Please check the blog for solution details.

The following depicts the architecture of the solution. The diagram is taken from the same blog.

Integration of Dynamics 365 with Azure Search (Relevance Search)

Technologies used

  • Dynamics CRM 365
  • Event Hub
  • Azure Search

Solution Overview

This solution is a preview feature available in Dynamics 365 named “Relevance Search”. Relevance search delivers fast and comprehensive search results in a single list sorted by relevance. It is designed to boost Dynamics 365.

All this information is available at TechNet.

The following diagram depicts the solution architecture of the relevance search. The diagram is taken from the Microsoft TechNet site
Relevance Search

Thursday, November 10, 2016

Duplication Detection Bugs in Dynamics 365

Duplicate Detection functionality has a bug in Dynamics 365. If you run a duplicate detection job or try to create a duplicate record, the system will display an empty duplicate detection dialog as shown in the screen shot below.


The Updated Record and Potential Duplicate Records grids do not show any records.

Also if you are updating records in the editable grid the system does not trigger the duplicate detection rules. The system will not display any duplicate detection dialog.

Monday, June 27, 2016

CRM and Azure Service Bus Integration Part 3

This is the third part of the series. Please check the last blog first, if you haven’t already.In this blog we go through a step by step tutorial to setup a CRM-Azure integration using service bus queue via SAS(Share Access Signature).


  • A CRM Online instance
  • Microsoft Azure account
  • Microsoft Azure SDK
  • Visual Studio 2013/2015
  • CRM2016 SDK V8.1 or later ( We will be using the plugin registration tool and sample code from the SDK 8.1 as the SAS featured is added to CRM2016 Update 1)

Setting up a Service Bus Namespace and Queue

For this post we will using the same Service Bus namespace we have created in the last post We will add a new queue to the existing Service Bus namespace.
  1. Login to Azure Portal.
  2. Select the Service Bus namespace. Click the “Queues” tab and select “Create A New Queue”

  3. Enter the values as shown in the following screenshot and click “Create A New Queue”
  4. A new queue will be created as shown in the screenshot.
  5. Double click on the queue name and select “Configure”. Change the general settings as required. I am using the default settings. Create a new policy to mange the access to the queue.

  6. Click on “DASHBOARD” and select “View Connection String” as shown in the screenshot.
  7. It will display the "access connection information" as shown in the following screenshot. Copy the connection string. It will be used in the next step.


Setting up the CRM Service Endpoint

Here are the steps
  1. Start the plugin registration tool. It is available in the \SDK\Tools location of the SDK. I am using SDK v8.1
  2. Click on Register>>Register New Service Endpoint
  3. It will prompt for the connection string. Paste the connection string for the queue here and click “Next”
  4. The registration tool will display the following page. It will prefill most of the values. I have updated the message format to JSON for this post. Click “Save” to save the service endpoint.
  5. Select the service endpoint and select "Register New Step", as shown in the screenshot.
  6. For this blog post I am using create message on account entity. You can chooses the other messages and entities as required. Click “Register New Step” to complete the registration.

Test the Integration

Queue integration does not require an active listener. So just create a new account from the front end. It should post a message to the queue. You can check status of the integration in the CRM system jobs. view.
Also, you can login to azure. Navigate to the queue and check the queue length. This column displays the number messages received by the queue.

Reading from the queue

Microsoft has provided the Azure sample. For this post, I am using the Azure sample code that comes with the CRM SDK. Here are the steps
  1. Open the “PersistentQueueListener” project from the location  \SDK\SampleCode\CS\Azure\PersistentQueueListener.
  2. Resolve the missing reference as done in the last blog post (
  3. Run the code. Provide the values for service namespace, issuer name and issuer secret.The code will read the message from the queue and display its contents.
    Note: The CRM sample code is using the ACS issuer name and issuer secret to generate SAS token. So please provide the ACS values as explained in the last blog.