Skip to main content
Pages and Files
101 Ways to Enhance Dynamics CRM with Azure
Business Process Flows
Business Rules (portable business logic)
Connecting to Dynamics CRM
CRM Hierarchical Data
CRM OData Examples
CRM Portals (Adxstudio)
CRM Web API
CRM-Azure Development - WebJobs
Add "All Pages"
Dynamics CRM and Azure Logic Apps
Example 1: Use an Azure Logic App to Send Reminders in Dynamics CRM
This example demonstrates how to use an
Azure Logic App
to trigger reminders (e.g., send an email, text message, etc.) for CRM Task records where the Due Date is in the past. Sending out alerts to employees when tasks are due can lead to improved customer satisfaction in many areas of a business.
In this example, I chose not to send e-mail messages from the Logic App itself. Although this is possible (e.g., using the Office 365 Send Email action), I chose instead to update the past-due task record so that a CRM workflow could then send the e-mail to the owner of the task, along with additional details from CRM if needed. In other words, I'm updating the past-due task to allow a CRM workflow to fire on the update event of the task to then carry on with further actions.
The Logic App solution is shown below. There are four main components:
A recurrence trigger runs the app every 3 minutes. I recommend setting the interval to 15 minutes or longer to avoid running the app too frequently and incurring
The HTTP action calls a web service to get back the current date/time in UTC format. This is needed to pass to the "List records" action. (Note that the
Logic Apps workflow definition language
has a function named utcNow, but I wasn't able to get it to work for this example.)
The List Records action queries Dynamics CRM Online for Task records that meet the criteria shown in the Filter Query. The OData filter statement uses the date/time that was retrieved in step 2. The "key-body-output" from the HTTP GET is used to inject the current date/time into the query filter. (Note: I set the Maximum Get Count field to 2 only to limit the number of records acted upon during development and testing; you can leave it blank or enter a different value.) Also, I chose to return only tasks records where the word "remind" is in the subject line, but you can use other criteria, such as including tasks with a Category set to "Reminder".
The For Each block updates each Task record retrieved. It simply updates the Duration field to the number 1. The update of the Duration field, or any other record update that you come up with, can then trigger a CRM workflow that can construct and send an e-mail to the owner of the task or a supervisor.
The Update Task record action above is too lengthy to show as an image, but here are the fields and values set:
Entity Name: Tasks
Record Identifier: Task
Subject: Subject (just write back the same subject)
One challenge with this Logic App was getting the current date and time. Although the Logic Apps definition language mentions a function named utcNow, I wasn't able to determine from the documentation how to use that function in place of the HTTP GET block that I ended up including.
Also, the Logic App builder isn't very intuitive at times. For example, after the List Records action that retrieves records from CRM, I added a For Each block using the drop-down menu, but the only option to loop through was the return value from the HTTP action, not the CRM records retrieved. It turns out that a For Each is automatically provided for the retrieval of CRM records, but this wasn't clear.
But enough complaining, I got this example working fairly quickly -- faster than it would've taken coding a cloud or Windows service app, and it has the benefit of being able to use other Logic App connectors if needed. Hopefully you can use this example as a starting point to build out similar functionality.
For a growing list of other ways to use Microsoft Azure with Dynamics CRM, see
Contact me at Altriva (email@example.com) if you have questions or want to talk about having Altriva implement something like this for your organization.
Example 2: Use an Azure Logic App to Alert when a System Job fails
: Query the Dynamics CRM Online system job records every 2 hours and, for those with a "Failed" status, send an e-mail to the admin with the details of each failed job. Process a maximum of 10 records.
: There are various ways to monitor (poll) CRM for new and updated records, including custom SDK-based code, recurring workflow execution tools, etc. Azure Logic Apps provides yet another way to do this. But Logic Apps is especially useful if you also need to utilize any of its 50+ connectors. For example, in the solution presented below, I utilized the Office 365 Email connector but could've also written the CRM records to a database, queue or other type of storage or SaaS service. Using Logic Apps opens up far more possibilities, when needed, than the workflow tool built-in to CRM.
This Logic App has four main components:
A recurrence trigger runs the app every 2 hours.
The HTTP action calls a web service to get back the date/time in UTC format that is two hours in the past. This is needed to pass to the "List records" action.
The List Records action queries Dynamics CRM Online for AsyncOperation records that meet the criteria shown in the Filter Query. The OData filter statement uses the date/time that was retrieved in step 2. The "key-body-output" from the HTTP GET is used to inject the date/time two hours in the past into the query filter. Note that id 31 is the "Failed" status code for a system job record.
The For Each block sends an e-mail using the Office 365 E-mail connector.
As with the first example on this page, I ran into one quirk with Logic Apps that I had to overcome by going into the Logic Apps "Code view". For the "Send an email" step, I wanted to include the system job name in the subject and body of the email. But the Logic Apps designer didn't present "name" as an option. So I went into the code view and replaced one of the available fields with "name" and it accepted it as a valid CRM field. So, it might be necessary at times to modify a Logic App definition in the code view, but hopefully Microsoft will eliminate most of the need to do so.
Example 3: Azure Logic App to Report on Neglected Dynamics 365 (CRM) Cases
View this solution here:
help on how to format text
Turn off "Getting Started"