|
| 1 | +--- |
| 2 | +title: Connect to Common Data Service |
| 3 | +description: Create and manage Common Data Service records by using Azure Logic Apps |
| 4 | +services: logic-apps |
| 5 | +ms.suite: integration |
| 6 | +ms.reviewer: jdaly, logicappspm |
| 7 | +ms.topic: conceptual |
| 8 | +ms.date: 05/05/2020 |
| 9 | +tags: connectors |
| 10 | +--- |
| 11 | + |
| 12 | +# Create and manage records in Common Data Service by using Azure Logic Apps |
| 13 | + |
| 14 | +With [Azure Logic Apps](../logic-apps/logic-apps-overview.md) and the [Common Data Service connector](https://docs.microsoft.com/connectors/commondataservice/), you can build automated workflows that manage records in your Common Data Service database. These workflows can create records, update records, and perform other operations. You can also get information from your Common Data Service database and make the output available for other actions to use in your logic app. For example, when a record is updated in your Common Data Service database, you can send an email by using the Office 365 Outlook connector. |
| 15 | + |
| 16 | +> [Common Data Service](https://powerapps.microsoft.com/common-data-service/) |
| 17 | +> lets you securely store and manage data that's used by business apps, such as Dynamics 365. |
| 18 | +> These apps use the Common Data Service |
| 19 | +> For more information, see |
| 20 | +> [What is Common Data Service](https://docs.microsoft.com/powerapps/maker/common-data-service/data-platform-intro)? |
| 21 | +
|
| 22 | +> [!IMPORTANT] |
| 23 | +> The [Common Data Service connector](https://docs.microsoft.com/connectors/commondataservice/) |
| 24 | +> replaces the Dynamics 365 connector, which is being deprecated, and has all the Dynamics 365 |
| 25 | +> connector's capabilities plus improvements that increase reliability. |
| 26 | +> |
| 27 | +> * For new logic apps, use the Common Data Service connector, rather than the Dynamics 365 connector. |
| 28 | +> After deprecation, Dynamics 365 connector actions won't be available for adding new actions. |
| 29 | +> |
| 30 | +> * For existing logic apps, you're not currently required to use the Common Data Service |
| 31 | +> connector or to stop using the Dynamics 365 connector, which will continue to work at this time. |
| 32 | +> |
| 33 | +> At some point, the [Common Data Service (Current Environment) connector](https://docs.microsoft.com/connectors/commondataserviceforapps/), |
| 34 | +> which is not yet available for logic apps, will replace both the Dynamics 365 connector and the |
| 35 | +> Common Data Service connector. At that point, both these connectors will be removed. For more |
| 36 | +> information, see the Power Platform blog post, [Dynamics 365 Connector is deprecated](https://docs.microsoft.com/power-platform/important-changes-coming). |
| 37 | +> |
| 38 | +> This article is updated to use the |
| 39 | +
|
| 40 | + |
| 41 | +This article shows how you can build a logic app that creates a task whenever a new record is created. |
| 42 | + |
| 43 | +## Prerequisites |
| 44 | + |
| 45 | +* An Azure subscription. If you don't have an Azure subscription, [sign up for a free Azure account](https://azure.microsoft.com/free/). |
| 46 | + |
| 47 | +* A [Common Data Service environment](https://dynamics.microsoft.com), which is a space where your organization stores, manages, and shares business data. For more information, see [Power Platform - Environments overview](https://docs.microsoft.com/power-platform/admin/environments-overview). |
| 48 | + |
| 49 | +* Basic knowledge about [how to create logic apps](../logic-apps/quickstart-create-first-logic-app-workflow.md) and the logic app where you want to access your Dynamics 365 account. To start your logic app with a Dynamics 365 trigger, you need a [blank logic app](../logic-apps/quickstart-create-first-logic-app-workflow.md). |
| 50 | + |
| 51 | +## Add Common Data Service trigger |
| 52 | + |
| 53 | +[!INCLUDE [Create connection general intro](../../includes/connectors-create-connection-general-intro.md)] |
| 54 | + |
| 55 | +For this example, add the Common Data Service trigger that fires when a new record is created. |
| 56 | + |
| 57 | +1. In the [Azure portal](https://portal.azure.com), open your blank logic app in Logic App Designer, if not open already. |
| 58 | + |
| 59 | +1. In the search box, enter `common data service`. For this example, under the triggers list, select this trigger: **When a record is created** |
| 60 | + |
| 61 | +  |
| 62 | + |
| 63 | +1. If prompted, sign in to the Common Data Service. |
| 64 | + |
| 65 | +1. In the trigger, provide information about the environment where you want to monitor for new "Leads" records, for example: |
| 66 | + |
| 67 | +  |
| 68 | + |
| 69 | + | Property | Required | Description | |
| 70 | + |----------|----------|-------------| |
| 71 | + | **Environment** | Yes | The environment to monitor, for example, "Fabrikam Sales Production". For more information, see [Power Platform - Environments overview](https://docs.microsoft.com/power-platform/admin/environments-overview). | |
| 72 | + | **Entity Name** | Yes | The entity to monitor, for example, "Leads" | |
| 73 | + | **Scope** | Yes | The source that created the new record, for example, a user in your business unit or any user in your organization. This example uses "Business unit". | |
| 74 | + |||| |
| 75 | + |
| 76 | +## Add Common Data Service action |
| 77 | + |
| 78 | +Now add a Common Data Service action that creates a task record for a new "Leads" record. |
| 79 | + |
| 80 | +1. Under the **When a record is created** trigger, select **New step**. |
| 81 | + |
| 82 | +1. In the search box, enter `common data service`. From the actions list, select this action: **Create a new record** |
| 83 | + |
| 84 | +  |
| 85 | + |
| 86 | +1. In the action, provide the information about the environment where you want to create the new task record. If available, other properties also appear based on the environment that you selected for this action, for example: |
| 87 | + |
| 88 | +  |
| 89 | + |
| 90 | + | Property | Required | Description | |
| 91 | + |----------|----------|-------------| |
| 92 | + | **Organization Name** | Yes | The environment where you want to create the record, which doesn't have to be the same environment in your trigger, but is "Fabrikam Sales Production" in this example | |
| 93 | + | **Entity Name** | Yes | The entity where you want to create the record, for example, "Tasks" | |
| 94 | + | **Subject** | Yes, by the environment in this example | A short description about the objective for this task. <p>1. | |
| 95 | + |||| |
| 96 | + |
| 97 | + 1. For the **Subject** property, From this list, select the property values that you want to include in the task record that's associated with the new lead record: |
| 98 | + |
| 99 | + | Property | Description | |
| 100 | + |-------|----------------| |
| 101 | + | **First Name** | The first name from the lead record to use the primary contact in the task record | |
| 102 | + | **Last Name** | The last name from the lead as the primary contact in the task record | |
| 103 | + | **Topic** | The descriptive name for the lead record in the record | |
| 104 | + | | | |
| 105 | + |
| 106 | +  |
| 107 | + |
| 108 | +1. Save your logic app. On the designer toolbar, select **Save**. |
| 109 | + |
| 110 | +1. To manually start the logic app, on the designer toolbar, select **Run**. |
| 111 | + |
| 112 | +1. Now create a lead record to test your logic app's workflow. |
| 113 | + |
| 114 | +## Add filter or query |
| 115 | + |
| 116 | +To specify how to filter data in a Dynamics 365 action, choose **Show advanced options** in that action. |
| 117 | +You can then add a filter or order by query. |
| 118 | +For example, you can use a filter query to get only the |
| 119 | +active accounts and order those records by account name. |
| 120 | +For this task, follow these steps: |
| 121 | + |
| 122 | +1. Under **Filter query**, enter this OData filter query: `statuscode eq 1` |
| 123 | + |
| 124 | +2. Under **Order By**, when the dynamic content list appears, |
| 125 | +select **Account Name**. |
| 126 | + |
| 127 | +  |
| 128 | + |
| 129 | +For more information, see these Dynamics 365 |
| 130 | +Customer Engagement Web API system query options: |
| 131 | + |
| 132 | +* [$filter](https://docs.microsoft.com/dynamics365/customer-engagement/developer/webapi/query-data-web-api#filter-results) |
| 133 | +* [$orderby](https://docs.microsoft.com/dynamics365/customer-engagement/developer/webapi/query-data-web-api#order-results) |
| 134 | + |
| 135 | +### Best practices for advanced options |
| 136 | + |
| 137 | +When you specify a value for a field in an action or trigger, |
| 138 | +the value's data type must match the field type whether you |
| 139 | +manually enter the value or select the value from the dynamic content list. |
| 140 | + |
| 141 | +This table describes some of field types and |
| 142 | +the required data types for their values. |
| 143 | + |
| 144 | +| Field type | Required data type | Description | |
| 145 | +|------------|--------------------|-------------| |
| 146 | +| Text fields | Single line of text | These fields require a single line of text or dynamic content that has the text type. <p><p>*Example fields*: **Description** and **Category** | |
| 147 | +| Integer fields | Whole number | Some fields require integer or dynamic content that has the integer type. <p><p>*Example fields*: **Percent Complete** and **Duration** | |
| 148 | +| Date fields | Date and Time | Some fields require a date with mm/dd/yyyy format or dynamic content that has the date type. <p><p>*Example fields*: **Created On**, **Start Date**, **Actual Start**, **Actual End**, and **Due Date** | |
| 149 | +| 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. | |
| 150 | +|||| |
| 151 | + |
| 152 | +Expanding on these field types, here are example fields in |
| 153 | +Dynamics 365 triggers and actions that require both a |
| 154 | +record ID and the lookup type. This requirement means |
| 155 | +values that you select from the dynamic list won't work. |
| 156 | + |
| 157 | +| Field | Description | |
| 158 | +|-------|-------------| |
| 159 | +| **Owner** | Must be either a valid user ID or team record ID. | |
| 160 | +| **Owner Type** | Must be either `systemusers` or `teams`. | |
| 161 | +| **Regarding** | Must be a valid record ID, such as an account ID or contact record ID. | |
| 162 | +| **Regarding Type** | Must be a lookup type, such as `accounts` or `contacts`. | |
| 163 | +| **Customer** | Must be a valid record ID, such as an account ID or contact record ID. | |
| 164 | +| **Customer Type** | Must be the lookup type, such as `accounts` or `contacts`. | |
| 165 | +||| |
| 166 | + |
| 167 | +In this example, the action named **Create a new record** creates a new task record: |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | +This action assigns the task record to a specific user ID or team record ID, |
| 172 | +based on the record ID in the **Owner** field and the lookup type in the **Owner Type** field: |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | +This action also adds an account record that's associated with the record ID |
| 177 | +added in the **Regarding** field and the lookup type in the **Regarding Type** field: |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | +## Find record ID |
| 182 | + |
| 183 | +To find a record ID, follow these steps: |
| 184 | + |
| 185 | +1. In Dynamics 365, open a record, such as an account record. |
| 186 | + |
| 187 | +2. On the actions toolbar, choose one of these steps: |
| 188 | + |
| 189 | + * Choose **Pop Out**.  |
| 190 | + * Choose **EMAIL A LINK** so you can copy the full URL into your default email program. |
| 191 | + |
| 192 | + The record ID appears in the URL between the `%7b` and `%7d` encoding characters: |
| 193 | + |
| 194 | +  |
| 195 | + |
| 196 | +## Connector reference |
| 197 | + |
| 198 | +For technical details, see the the [connector's reference page](/connectors/dynamicscrmonline/). |
| 199 | + |
| 200 | +## Next steps |
| 201 | + |
| 202 | +[Diagnose logic app failures](../logic-apps/logic-apps-diagnosing-failures.md) |
| 203 | + |
| 204 | +* Learn about other [Logic Apps connectors](../connectors/apis-list.md) |
0 commit comments