Skip to main content

Deep Dive into Dynamics 365 & Azure Cosmos DB using Azure Logic Apps

Logic Apps

Logic Apps helps you build, schedule, and automate processes as workflows so you can integrate apps, data, systems, and services across enterprises or organizations.
To build integration solutions with logic apps, we can choose from a growing gallery of ~200 built-in connectors, such as Dynamics 365, SQL Database, Azure services (Azure Cosmos DB, Azure Table Service, etc.), Office 365, Salesforce, Google, and more. These connectors provide triggers, actions, or both for creating logic apps that securely access and process data in real time.

Benefits of using Azure Logic Apps:

  • Out-of-the-box connectors reduce integration challenges
  • Faster development using Logic App Templates
  • Re-usability of the Logic Apps
  • Pay only for what you use

Use Case

Today, we'll be looking at listing Dynamics 365 records, using Logic Apps, and then performing some processing on the data (sending email to retrieved accounts, storing contact email id in an Array Variable) and finally dumping the data on Azure Cosmos DB. 

Here is my Dynamics 365 trial instance:


On a daily basic, I want to retrieve all the Account records which have Ownership as "Public". After retrieving the records, I want to send each one of them an Email about some changes to policies, and then finally I want to save the Accounts Email information in Azure Cosmos DB. 

Currently, in my Dynamics 365 instance, I have 5 such records which are having Public Ownership. Hence we should get 5 emails from the Logic App, and 1 record in Azure Cosmos DB with Email information of all 5 Accounts in a serialized Array form.

Let's Develop the Logic App

This blog covers following sections in detail:

  1. List Dynamics 365 Records using Logic Apps
  2. Send Email from Logic App to the Accounts Retrieved from Dynamics 365
  3. Create a Document in Azure Cosmos DB from Azure Logic App
We will be developing the Logic App directly from the Azure Portal. 
Now lets go over steps for each one of them:

  1. List Dynamics 365 Records using Logic Apps

  1. Create a new Logic App Service in Azure Portal

  1. Select Recurrence from the Logic App Templates

  1. Specify recurrence properties as shown below:

  1. Initialize Variables - ContactEmail of type String, and ListOfContacts of type Array.

  1. Add a new Action, select type as Dynamics 365

  1. Select List Records from list of available operations under Dynamics 365.

  1. You will be prompted to log in to your Dynamics 365 organization. Provide your credentials and click on OK.

  1. Once you are logged in successfully, Select Organization Name and Entity Name from the dropdown as shown below. Also apply a filter criteria for selecting only Public Ownership Accounts.

  1. Add a new For Each loop from New Step


  1. In Output of previous step, select value from dynamics content popup.

NOTE - By default the For Each loop is designed to run in parallel, just like Parallel.ForEach in C#. If you wish to override this behavior, then go to options of the ForEach, and specify Concurrency options as mentioned below:


  1. Within For Each step, select Add Action.

  1. From list of available actions, select Set Variable, and set the previously initialized variable as shown below:

  1. Click on Save.
This marks completion of First Section - Listing Records from Dynamics 365 using Logic Apps, and looping over the result set.


  1. Send Email from Logic App to the Accounts Retrieved from Dynamics 365

  1. Add a new Action - Select Outlook from list of available Actions

  1. Select Send an Email from list of operations available

  1. You will be prompted to specify your Outlook credentials. Once you enter your credentials, the Logic App will internally create a connection to your Outlook Account, and will utilize that connection to send emails.

  1. Then you would need to specify Email properties like To, Subject and Body.

  1. Click on Save.
Now our Step to send out Emails to each Account is also set up. Next we will look into saving Accounts data in Azure Cosmos DB.


  1. Create a Document in Azure Cosmos DB from Azure Logic App

  1. Just below to the previous For Each Step, Add a new Action, and select Cosmos DB From available Connectors.

  1. Select Create or Update Document from listed Actions.

  1. Select the Azure Cosmos DB account listed below, and give a friendly name to this Connection. Then Click on Create.

  1. Select Database ID, Collection ID from the dropdown, and specify a JSON message in Document section as shown below:
  1. Click on Save.
That's All. We are all set with the Logic App now.

Run the Logic App

Even though we have set the trigger interval for Logic App as 1 Day, for testing purposes, we can directly Run the Logic App from the Azure portal. So when we run the Logic App that we just developed, we can see the execution results in a neat flow on the Azure Portal, with Pass/Fail results for each step of the Logic App.


Clearly we can see from the image above that All our steps were executed successfully.
Now lets check the output one by one. First we will check the emails (For testing purpose, I have sent all the mails to my mail ID), below is an image showing 5 mails that I have juts received from the Logic App:


Also, here is an image of the Document that is just created in Azure Cosmos DB account from the Logic App:


References:

https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-overview
https://azure.microsoft.com/en-in/services/logic-apps/

Comments

  1. Very useful information, Keep Update with us Azure Online Training

    ReplyDelete
  2. Azure app meet rigorous performance, scalability, security and compliance requirements while using a fully managed platform to perform infrastructure maintenance. Quickly create powerful cloud apps using a fully managed platform from Impiger technologies. Impiger provides amazing service.

    ReplyDelete
  3. Thank you for sharing such great information very useful to us. This is good information and really helpful for the people who need information about this Thank you for sharing any good knowledge and thanks for fantastic efforts. Good information. Thanks for sharing with us
    oracle training in chennai

    oracle training institute in chennai

    oracle training in bangalore

    oracle training in hyderabad

    oracle training

    hadoop training in chennai

    hadoop training in bangalore



    ReplyDelete

Post a Comment

Popular posts from this blog

Handling Concurrency in Azure Functions (HTTP Triggered)

Concurrency & Isolation Concurrency is one of the most common requirements when we don't want the resource to be accessed by multiple requests at the same time. Lets say we have a Database that holds products stock information, then it is very important that any read/write operation that happens on the Database must hold the property of Isolation . The isolation property ensures that the concurrent execution of transactions results in a system state that would be obtained if transactions were executed sequentially, i.e., one after the other. Providing isolation is the main goal of concurrency control. Depending on the concurrency control method (i.e., if it uses strict – as opposed to relaxed – serializability), the effects of an incomplete transaction might not even be visible to another transaction. Options Available in Azure Functions Recently while working on Azure Functions, I discovered a really simple way of handling Concurrency via code. There are ways to con

Azure Functions - Retrieve data from Dynamics 365 CRM/CE Online using CRM OData Web API

Introduction: This blog describes how you can retrieve data from Dynamics 365 CRM/CE Online in an Azure Function, using CRM OData Web API. The CRM Web API has a couple of advantages over the traditional SOAP based approach to interact with CRM. These are rest based services, its easy to use and transport over http protocol , and there is no need to use additional web resources (XrmServiceToolkit ) of SDK (SDK.REST). Here is a detailed documentation on CRM OData Wbeb API. I will be using an Azure Function Application in Visual Studio 2017 to retrieve records from Dynamics 365 CRM/CE, by making use of OData API Endpoint provided by CRM. Prerequisites: Dynamics 365 CRM Online Trial https://trials.dynamics.com/ https://signup.microsoft.com/Signup?OfferId=bd569279-37f5-4f5c-99d0-425873bb9a4b&dl=DYN365_ENTERPRISE_PLAN1&Culture=en-us&Country=us&ali=1 Azure Subscription related to CRM Online instance https://portal.azure.com/ Visual Studio 2017 with Cl

Retrieve 5000+ Records in Dynamics 365 CE using CRM OData, Fetch XML and C#

If you want to retrieve 5000+ records in Dynamics 365 CE, you need to make use of Paging concept of CRM. By default 5000 records are retrieved in a single OData call in CRM. To get more, you need to make subsequent calls to OData Endpoint by passing a paging cookie in the request. I will be using a simple C# Console Application to retrieve 5000+ records from Dynamics 365 CE, by making use of OData API Endpoint provided by CRM and passing Fetch XML in OData Call . Concept: CRM OData Endpoints allows us to use Fetch XML to retrieve data from Microsoft Dynamics 365 CE.  If your resultset has more than 5000 records, you will be returned with first 5000 records ONLY in one OData call. To know if the resultset has more than 5000 records, we make use of the response from OData call. The response is added with a cookie value contained in a key - "@Microsoft.Dynamics.CRM.fetchxmlpagingcookie" If you wish to fetch the next set of resultset data, you will have to pass this c