With Azure Logic Apps and Dynamics 365 Connector you can create automated tasks and workflows based on Dynamics 365 records. The workflow can create records, update items, return records, etc. with Dynamics 365 account. You can include actions in logic applications that accept responses from Dynamics 365 and make their output available for other actions. For example, when items are updated in Dynamics 365, you can use Office 365 to send e-mails.
In this article, I will show you how to create a logic application to create a task with Dynamics 365 each time a new lead record is created in Dynamics 365.
Preconditions
- Dynamics 365 account
- Logic application you want to access Dynamics 365 account. To launch a logic application with Dynamics 365 trigger, you need an empty logic application
- Basic knowledge on how to create logic applications
- Azure Subscription. If you do not have an Azure subscription, please sign up for a free Azure account.
Add Dynamics 365 trigger
Before a logic application accesses a service, you need to create a connection between the logic application and its service. If you have not created this connection before, add a trigger or action for that service to the logic application and you will be prompted for connection information. Logic Apps Designer makes it easy to create this connection directly from the logic application.
First, add a Dynamics 365 trigger that occurs when Dynamics 365 displays a new lead record.
1 – If it is not already open in the Azure portal, open an empty logic application in Logic App Designer.
2 – In the search box, enter “Dynamics 365” as a filter. In this example, under the trigger list, select this trigger. When a record is created
3 – When you are asked to sign in to Dynamics 365, sign in now.
4 – Enter the details of these triggers.
Property | Required | Description |
Organization Name | Yes | The name for your organization’s Dynamics 365 instance to monitor, for example, “Contoso” |
Entity Name | Yes | The name for the entity to monitor, for example, “Leads” |
Frequency | Yes | The unit of time to use with intervals when checking for updates related to the trigger |
Interval | Yes | The number of seconds, minutes, hours, days, weeks, or months that pass before the next check |
Add Dynamics 365 action
Next, add a Dynamics 365 action to create a task record for the new lead record.
1 – Under Trigger, select New Step.
2- In the search box, enter “Dynamics 365” as a filter. From the action list, select this action. Create a new record.
3 – Please enter the following action details.
Property | Required | Description |
Organization Name | Yes | The Dynamics 365 instance where you want to create the record, which doesn’t have to be the same instance in your trigger, but is “Contoso” in this example |
Entity Name | Yes | The entity where you want to create the record, for example, “Tasks” |
4 – When the Subject box appears in the action, click in the Subject box to display the dynamic content list. From this list, select the field value to include in the task record associated with the new lead record.
Field | Description |
Last name | The last name from the lead as the primary contact in the record |
Topic | The descriptive name for the lead in the record |
5 – On the designer’s toolbar, choose Save to Logic Application.
6 – To start the logic application manually, select [Run] on the designer’s toolbar.
7 – Create a lead record in Dynamics 365 so that it can trigger the workflow of logic application.
Add a filter or query
To specify how Dynamics 365 action data is filtered, select Show advanced options for that action. You can then add filters or orders in the query. For example, you can use filter queries to get only active partners and sort them by partner name. For this task, follow these steps:
1 – In Filter Query, enter this OData filter query. statuscode eq 1
2 – In Sort, when the dynamic content list is displayed, select Account name.
Advanced option best practices
When you specify a value for a field in an action or trigger, regardless of whether you manually enter a value or select a value from the dynamic content list, the data type of the value must match the field type.
This table explains several field types and the data types required for their values.
Field type | Required data type | Description |
Text fields | Single line of text | These fields require a single line of text or dynamic content that has the text type. Example fields: Description and Category |
Integer fields | Whole number | Some fields require integer or dynamic content that has the integer type. Example fields: Percent Complete and Duration |
Date fields | Date and Time | Some fields require a date with mm/dd/yyyy format or dynamic content that has the date type. Example fields: Created On, Start Date, Actual Start, Actual End, and Due Date |
Fields requiring both a record ID and lookup type | Primary key | Some fields that reference another entity record require both a record ID and a lookup type. |
The sample fields for Dynamics 365 triggers and actions that extend both of these field types, requiring both a record ID and a lookup type are: This requirement means that the value chosen from the dynamic list does not work.
Field | Description |
Owner | Must be either a valid user ID or team record ID. |
Owner Type | Must be either systemusers or teams. |
Regarding | Must be a valid record ID, such as an account ID or contact record ID. |
Regarding Type | Must be a lookup type, such as accounts or contacts. |
Customer | Must be a valid record ID, such as an account ID or contact record ID. |
Customer Type | Must be the lookup type, such as accounts or contacts. |
In this example, an action named “Create a new record” creates a new task record.
This action assigns a task record to a specific user ID or team record ID based on the record ID of the Owner field and the lookup type in the Owner Type.
This action also adds the record ID added to the Partner field and the partner record associated with the reference type in the Type of opponent field.
Search record ID
To find the record ID, follow these steps:
1 – In Dynamics 365, open a record such as a business partner record.
2 – On the action toolbar, select one of the following procedures.
- Choose Pop Out.
- Choose Link by E – mail so that you can copy the complete URL to the default e – mail program.
The record ID is displayed between encoded characters% 7b and% 7d in the URL.
Troubleshooting a failed run
In order to find and confirm steps that failed in the logic application, you can display the execution history, status, input, output etc of the logic application.
1 – On the Azure portal logic application main menu, select [Overview]. Display all execution status of the logic application In the execution history section, select Execute Failed for Details
2 – Expand failed steps so that you can view details.
3 – Confirm the step details such as input and output. This will help you find the cause of the failure