Example 1: Use an Azure Logic App to identify Dynamics 365 users who didn't perform a required action in the past day. Send email with user names.

This example of using Azure Logic Apps with Dynamics 365/CRM (D365) demonstrates one way to meet the following requirement:

Each day, identify D365 users who have not created at least one task record in the previous day. Send an email with the list of those users.

Someone asked about how to meet this requirement on the D365 forum. Dynamics 365 itself does not provide a no-code way of meeting this requirement, but with Azure Logic Apps it's possible to meet this requirement by connecting built-in Logic Apps functionality along with formulas using the Workflow Definition Language.

Note: According to Microsoft's pricing for Logic Apps, it will cost less than a penny a day to run this Logic App. However, it's important to periodically monitor Microsoft's billing for your Azure services to be sure you are keeping your costs to a minimum.

The next section provides the Logic App workflow diagram, with most details expanded. The section below the diagram provides further details on how to build this workflow.

Logic App workflow diagram


Logic App Details

The table below lists each of the Logic App components and a description and details for each component.
Component Name
Run the Logic App once per day. Use the advanced options to run the app at a particular time of day based on your requirements.
Initialize string variable
Initialize a string variable to store the Dynamics 365 users who meet the criteria in the app
List D365 users
Query Dynamics 365 for active users. Provide the following as the Filter Query: isdisabled eq false
For each
A looping component to loop through the Dynamics 365 users returned from "List D365 users"
The Compose action is used to formulate a Dynamics 365 ODATA query for the next action, "List tasks for user". The Compose action's expression is the following:

@concat('_createdby_value eq ', items('For_each')?['systemuserid'], ' and createdon gt ', adddays(utcnow(), -1) )

The adddays function uses utcnow with negative one to formulate a date one day ago. Adjust this date criteria to meet your specific requirements.
List tasks for user
Query Dynamics 365 for Task records that meet the filter criteria as formulated in the previous Compose action. Set the Filter Query field of the D365 query to the results of the Compose action.
Check for any tasks
This Condition block checks whether the query for D365 tasks returned any records for the system user.

@equals(empty(body('List_tasks_for_user')['value']), true)

If the action "List tasks for user" did not return any records then the equals function results in a true value.
If true: Add D365 user's name
The "If true" block includes a Compose block named "Add D365 user's name to string variable". This action adds the D365 user's first name, last name and email address to the string variable defined earlier.
Check whether any D365 users have zero tasks
The Condition "Check whether any D365 users have zero tasks" checks the length of the string variable using the following expression:

@equals(length(variables('UsersWithZeroTasks')), 0)

This is necessary to avoid sending an email unnecessarily.
If false, Send an email
This action uses Office 365 to send an email. The body of the email is set to the string variable, which contains a list of one or more D365 users.

Other ways to meet this requirement includes:
  • In Dynamics 365: Custom Action and Dynamics 365 plug-in. Create a custom action then create and register a plug-in that runs when the action is called. Invoke the action using an Azure scheduled job (e.g., Azure Function) or Windows scheduled task.
  • Azure Function: Use an Azure Function to provide all of the functionality. Schedule the function to run once per day.