Connect to Dynamics 365 from logic app workflows
With Logic Apps, you can connect to Dynamics 365 (online) and create useful business flows that create records, update items, or return a list of records. With the Dynamics 365 connector, you can:
- Build your business flow based on the data you get from Dynamics 365 (online).
- Use actions that get a response and then make the output available for other actions. For example, when an item is updated in Dynamics 365 (online), you can send an email using Office 365.
This topic shows you how to create a logic app that creates a task in Dynamics 365 whenever a new lead is created in Dynamics 365.
- An Azure account.
- A Dynamics 365 (online) account.
Create a task when a new lead is created in Dynamics 365
In the Azure search box, type
Logic apps, and press ENTER.
Under Logic apps, click Add.
To create the logic app, complete the Name, Subscription, Resource Group, and Location fields, and then click Create.
Select the new logic app. When you receive the Deployment Succeeded notification, click Refresh.
Under Development Tools, click Logic App Designer. In the template list, click Blank Logic App.
In the search box, type
Dynamics 365. From the Dynamics 365 triggers list, select Dynamics 365 – When a record is created.
If you are prompted to sign in to Dynamics 365, do so now.
In the trigger details, enter the following information:
Organization Name. Select the Dynamics 365 instance that you want the logic app to listen to.
Entity Name. Select the entity that you want to listen to. This event acts as a trigger to start the logic app. In this walkthrough, Leads is selected.
How often do you want to check for items? These values set how often the logic app checks for updates related to the trigger. The default setting is to check for updates every three minutes.
Frequency. Select seconds, minutes, hours, or days.
Interval. Enter the number of seconds, minutes, hours, or days that you want to pass before the next check.
Click New step, and then click Add an action.
In the search box, type
Dynamics 365. From the actions list, select Dynamics 365 – Create a new record.
Enter the following information:
Organization Name. Select the Dynamics 365 instance where you want the flow to create the record. Notice that this instance doesn’t have to be the same instance where the event is triggered from.
Entity Name. Select the entity that you want to create a record when the event is triggered. In this walkthrough, Tasks is selected.
Click in the Subject box that appears. From the dynamic content list that appears, you can select either of these fields:
- Last Name. Selecting this field inserts the last name for the lead into the Subject field for the task, when the task record is created.
Topic. Selecting this field inserts the Topic field for the lead into the Subject field for the task, when the task record is created. Click Topic to add that to the Subject box.
On the Logic App Designer toolbar, click Save.
To start the Logic App, click Run.
Now create a lead record in Dynamics 365 for Sales and see your flow in action!
Set advanced options for a logic app step
To specify how to filter data in a logic app step, click Show advanced options in that step, then add a filter or order by query.
For example, you can use a filter query to get only active accounts and order by the account name.
To perform this task, enter the OData filter query
statuscode eq 1,
and select Account Name from the dynamic content list.
More information: MSDN: $filter
Best practices when using advanced options
When you add a value to a field, you must match the field type whether you type a value or select a value from the dynamic content list.
|Field type||How to use||Where to find||Name||Data type|
|Text fields||Text fields require a single line of text or dynamic content that is a text type field. Examples include the Category and Sub-Category fields.||Settings > Customizations > Customize the System > Entities > Task > Fields||category||Single Line of Text|
|Integer fields||Some fields require integer or dynamic content that is an integer type field. Examples include Percent Complete and Duration.||Settings > Customizations > Customize the System > Entities > Task > Fields||percentcomplete||Whole Number|
|Date fields||Some fields require a date entered in mm/dd/yyyy format or dynamic content that is a date type field. Examples include Created On, Start Date, Actual Start, Last on Hold Time, Actual End, and Due Date.||Settings > Customizations > Customize the System > Entities > Task > Fields||createdon||Date and Time|
|Fields that require both a record ID and lookup type||Some fields that reference another entity record require both the record ID and the lookup type.||Settings > Customizations > Customize the System > Entities > Account > Fields||accountid||Primary Key|
More examples of fields that require both a record ID and lookup type
Expanding on the previous table, here are more examples of fields that don't work with values selected from the dynamic content list. Instead, these fields require both a record ID and lookup type entered into the fields in PowerApps.
- Owner and Owner Type. The Owner field must be a valid user or team record ID. The Owner Type must be either systemusers or teams.
- Customer and Customer Type. The Customer field must be a valid account or contact record ID. The Owner Type must be either accounts or contacts.
- Regarding and Regarding Type. The Regarding field must be a valid record ID, such as an account or contact record ID. The Regarding Type must be the lookup type for the record, such as accounts or contacts.
The following task creation action example adds an account record that corresponds to the record ID adding it to the regarding field of the task.
This example also assigns the task to a specific user based on the user's record ID.
To find a record's ID, see the following section: Find the record ID
Find the record ID
Open a record, such as an account record.
On the actions toolbar, click Pop Out . Alternatively, on the actions toolbar, to copy the full URL into your default email program, click EMAIL A LINK.
The record ID is displayed in between the %7b and %7d encoding characters of the URL.
To troubleshoot a failed step in a logic app, view the status details of the event.
Under Logic Apps, select your logic app, and then click Overview.
The Summary area is shown and provides the run status for the logic app.
To view more information about any failed runs, click the failed event. To expand a failed step, click that step.
The step details appear and can help troubleshoot the cause of the failure.
For more information about troubleshooting logic apps, see Diagnosing logic app failures.
View any triggers and actions defined in the swagger, and also see any limits in the connector details.
Explore the other available connectors in Logic Apps at our APIs list.