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
https://docs.microsoft.com/en-us/azure/azure-functions/functions-compare-logic-apps-ms-flow-webjobs#flow-vs-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.

    2017-01-05_16-01-49
  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)

    2017-01-05_16-05-45
  4. Open the newly created app.

    2017-01-09_21-37-24
  5. Click on Edit to open the designer.

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

    2017-01-07_22-35-44
  7. Enter the JSON schema for the request. I have created a customer object with first name, last name, street address and city.

    2017-01-08_17-41-31
  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.

    2017-01-08_17-44-13
  10. Select Dynamics 365 – Create a new record from the managed APIs list.

    2017-01-08_17-46-17
  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.

    2017-01-08_17-47-52
  12. Click New step and choose Add an action as shown in the screen shot below.

    2017-01-08_17-49-19
  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.

2017-01-09_22-31-29

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.

    2017-01-09_22-38-28
  2. Enter the URL copied from the Request.
  3. Enter the Headers as shown in the screen shot below. The endpoints are expecting JSON.

    2017-01-09_22-43-28
  4. Enter the Body and Click Send. The  Logic App will return the customer id as shown in the screen shot below.

    2017-01-09_22-50-39
  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.

    2017-01-09_22-56-07


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.

    2016-12-13_16-04-47
  • 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. https://msdn.microsoft.com/en-us/library/gg328457.aspx#BKMK_CustomIcons. 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";  
       break;  
     case 2:  
       imgName = "new_/images/yellow.png";  
       tooltip = "Noraml Priority Case";  
       break;  
     case 3:  
       imgName = "new_/images/green.png";  
       tooltip = "Low Priority Case";  
       break;  
     default:  
       imgName = "";  
       tooltip = "";  
       break;  
   }  
   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”

    2016-12-13_16-23-09
  • Specify the JavaScript web resource and function name.

    2016-12-13_16-25-30

Results

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.

2016-12-13_16-46-25

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

Code

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 = Xrm.Page.data.entity.attributes.get('name');  
   //get the value name attribute  
   var accountNameValue = accountName.getValue();  
   //if the account name is null then return  
   if (accountName.getValue() == null) {  
     return;  
   }  
   //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, ''));  
       myControl.clearNotification('my_unique_id');  
     }];  
     myControl.addNotification({  
       messages: ['Number/s in the account name'],  
       notificationLevel: 'RECOMMENDATION',  
       uniqueId: 'my_unique_id',  
       actions: [actionCollection]  
     });  
   }  
 }  

Results

2016-11-25_22-36-28

When the user clicks “Apply”, the system removes the number 7 from the name.
2016-11-25_22-36-56

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.
2016-11-17_11-15-32
Steps
  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:
https://msdn.microsoft.com/magazine/mt788623. Please check the blog for solution details.

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

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.
https://technet.microsoft.com/en-us/library/mt723654.aspx#BKMK_Architecture

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.

2016-11-11_15-00-25

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).

Prerequisite

  • 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 http://mscrmshop.blogspot.com.au/2016/06/crm-and-azure-service-bus-integration_20.html. 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”

    2016-06-22_14-28-05
  3. Enter the values as shown in the following screenshot and click “Create A New Queue”
    2016-06-22_14-30-18
  4. A new queue will be created as shown in the screenshot.
    2016-06-22_14-30-58
  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.
    2016-06-27_13-40-12

    2016-06-27_13-44-54
  6. Click on “DASHBOARD” and select “View Connection String” as shown in the screenshot.
    2016-06-27_13-51-04
  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.

    2016-06-27_13-53-43

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
    2016-06-28_10-45-05 
  3. It will prompt for the connection string. Paste the connection string for the queue here and click “Next”
    2016-06-27_13-59-12
  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.
    2016-06-27_14-08-15
  5. Select the service endpoint and select "Register New Step", as shown in the screenshot.
    2016-06-28_10-48-23
  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.
    2016-06-22_14-37-09

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.
2016-06-22_14-44-17

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 (http://mscrmshop.blogspot.com.au/2016/06/crm-and-azure-service-bus-integration_20.html)
  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.
    2016-06-22_14-59-06

Monday, June 20, 2016

CRM and Azure Service Bus Integration Part 2

This is the second part of the series. We have discussed the contract types, security and a general overview of CRM–Azure Service Bus integration in the previous blog. Please read part 1 for the context.
In this blog we go through a step by step tutorial to setup a CRM-Azure Service Bus one way listener contract using ACS.

Prerequisite

  • A CRM Online instance
  • Microsoft Azure account
  • Microsoft Azure SDK
  • Visual Studio 2013/2015
  • CRM2016 SDK V8.0.1 or less ( We will be using the plugin registration tool and sample code from the SDK. The plugin registration tool does not have ACS options from SDK v8.1 onwards)
Here are the steps to create the integration.

Setting up a Service Bus Namespace

The first thing you need for the integration is a Service Bus namespace. If you already have an ACS namespace, you can skip this step.
In the past you could login to the Azure portal and create an ACS namespace. But now, Azure portal does not allow the creation of ACS namespaces from the portal. It only creates a SAS namespace by default. We need to use PowerShell to create an ACS namespace.
  1. Open “Windows PowerShell ISE”
  2. Type Add-AzureAccount. It will open the login dialog. Enter the username and password for your Azure account and press login.If everything goes smoothly, the PowerShell output will look like the following screenshot.

    2016-06-17_16-38-46
  3. Type the following command below to create a Service Bus namespace. Replace ‘MSCRMShopBus’ with the namespace you want and press enter

     New-AzureSBNamespace -Name "MSCRMShopBus" -Location "Australia East" -CreateACSNamespace $true  -NamespaceType Messaging. Replace the parameters values as required. 
  4. The output screen will look like the following screenshot. It will create a namespaces for both ACS and SAS.

    2016-06-17_16-44-52
  5. This step is optional. Login to your Azure account and check the connection information of the Service Bus namespace. It will look like the following screen.

    2016-06-20_09-28-49

    2016-06-20_11-35-17

Get the Certificate file and Issuer name for CRM

For CRM Online
To get the security certificate and the issuer name for CRM go to Settings>>Customizations>>Developer Resources. Download the certificate file and also notice the issuer name of the certificate.

2016-06-14_23-05-37
For CRM On Premise
For CRM on premise, follow the following article for step by step instructions.
https://msdn.microsoft.com/en-us/library/gg328249.aspx

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.0.1.
  2. Click on Register>>Register New Service Endpoint
    2016-06-20_10-29-12
  3. It will open the the following page. Enter the Values as required and press “ Save & Configure ACS”.
    2016-06-20_10-31-46
    Solution Name is the Service Bus namespace we created in the beginning of this blog.

    Path is the path of your listener project. For example, when you run the listener project for a one-way listener for this blog, the service endpoint URL will look like https://mscrmshopbus.servicebus.windows.net/RemoteService
. The red part of the URL represents the path.

Contract is the type of contract we are using for the service endpoint. For the difference types of contracts check the last blog.
  • The registration tool will display the following screen. Enter the information below and press “Configure ACS”. Management Key is the default key when you create a Service Bus namespace. The certificate file and issuer name comes from the “Get the Certificate file and Issuer name for CRM” section of the blog.
    2016-06-20_10-55-54
  • Press “Yes” on the following screen.
    2016-06-15_22-39-57
  • It will create the management service, rulegroup and sample rules for the service endpoint. Press “Close”.
    2016-06-20_11-04-02
  • Press “Save & Verify Authentication”.It will test the authentication and save the configuration of the service endpoint. Press Close to close the screen.

    2016-06-20_11-08-40
  • Press “Save” to close the service endpoint registration screen.
  • Add a new step to the service endpoint as shown in the screenshot below. It is exactly the same as registering the step for a plugin assembly.

    2016-06-20_11-11-56
  • For this blog, I am creating a step for on creation of a new account. Choose the step values as required or copy the values as shown in the screenshot.
    2016-06-20_11-15-15

    Setting up a listener application

    1. For this blog, I am using the Azure sample code that comes with the CRM SDK. Open the “OnewayListener” project from the location  \SDK\SampleCode\CS\Azure\OneWayListener.
    2. Resolve the missing references. The 2 highlighted DLLs are available in the Azure SDK.

      2016-06-20_11-25-39
    3. Run the sample code. It will prompt for the following information.

      2016-06-20_11-29-27
      Service Namespace is the Service Bus namespace.
      Issuer name is the “Default Issuer”  on the Service Bus connection information as shown in the step 5 of “Setting up a service bus namespace”. It is not the issuer name in CRM Online.
      Issuer Secret is the “Default Key” on the Service Bus connection information.
    4. If everything is working properly it will display the service address as shown in the screenshot of step 3.

    Testing the integration

    1. The listener application should be up and running.
    2. Login to CRM and create a new account. If everything is working properly, it will display the data context in the listener application.
      2016-06-20_13-41-25
    3. To check the status of the jobs you can go to the “System Jobs” view.
      2016-06-20_13-44-56
    4. If the listener application is not available, the status of the job will change to “Waiting for Retry”. It will keep trying to post the message and ultimately change to “failed” if it is not successful after X number of tries. The screenshot below display the details of the job with the status “waiting for retry”.

      2016-06-20_13-53-14