# Quickstart - Records

> The purpose of this guide is to help you create a working sample that uses the following Microsoft Dynamics 365 activities:

## Overview

The purpose of this guide is to help you create a working sample that uses the following Microsoft Dynamics 365 activities:

* [Insert Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-insert-record)
* [Search Records](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-search-records)
* [Get Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-get-record)
* [Delete Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-delete-record)

This working sample enables you to quickly verify the connection to your Microsoft Dynamics 365 application and get familiar with the activity's input/output datatypes.

After completing the steps in this guide, you'll have an automation sequence that does the following:

1. Establishes a connection to your Microsoft Dynamics 365 application ([Get Credential](https://docs.uipath.com/activities/other/latest/workflow/get-robot-credential) and [Microsoft Dynamics Application Scope](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-scope)).
2. Inserts a new account record ([Insert Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-insert-record)).
3. Searches for the inserted account record ([Search Records](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-search-records)).
4. Updates the website field of the account record ([Update Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-update-record)).
5. Verifies the account record was successfully updated ([Get Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-get-record)).
6. Deletes the inserted account record ([Delete Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-delete-record)).
   :::note
   While there may be more efficient ways of achieving the same result, the goal of this sequence is to demonstrate all of the record activities.
   :::

## Prerequisites

Before you begin:

1. Complete the Microsoft Dynamics 365 [Setup](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-setup) steps.
2. Use the [Package Manager](https://docs.uipath.com/studio/docs/managing-activities-packages) to install the **Microsoft.Activities.Extensions** package (this is for the **Search Records** activity).
   :::note
   This guide uses *ClientCredentials* as the **AuthenticationType** in the [Microsoft Dynamics Application Scope](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-scope) activity. If you prefer to use *PasswordCredentials*, you can skip step 1 (add a **Get Credential** activity) and follow the bulleted substeps in step 2 (add the **Microsoft Dynamics Application Scope** activity).
   :::

## Steps

### Build your project

1. Add a [Get Credential](https://docs.uipath.com/activities/other/latest/workflow/get-robot-credential) activity.
2. Enter the **AssetName** for the credential asset you created (during the **Setup**) for the application **Client Secret** (e.g., *"MicrosoftDynamics365ClientCredentials"*).
3. Create and enter a `SecureString` variable for the **Password** property (e.g., *clientSecret*).
4. Create and enter a `String` variable for the **Username** property (e.g, *clientId*).
5. Add the [Microsoft Dynamics 365 Application Scope](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-scope) activity after the **Get Credential** activity.
6. Click the **Configure** button (this opens the **Connection Wizard**), select your **AuthenticationType**, enter your credentials, and click the **Test Connection** button. For more information about the purpose and behavior of this wizard, see the section.
   * This step is for design time purposes only. To populate the **Microsoft Dynamics Application Scope** properties, continue to complete the steps below.
7. In the **AuthenticationType** property, select your preferred authentication type.
   * If you select *PasswordCredentials*, create a `String` variable for the **ClientId** (e.g., **Name**: *clientId* **Default**: *"56X9aXXX-b5d9-4a90-XXXX-13XX9643XXXX"*)
8. In the **ClientId** property, enter the `String` variable you created for the **Get Credential** activity or substep above (e.g., *clientId*).
9. In the **ClientSecret** property, enter the `SecureString` variable you created for the **Get Credential** activity (e.g., *clientSecret*).
   * If you selected *PasswordCredentials* leave the **ClientSecret** property empty.
10. In the **EndpointUrl** property, create and enter a `String` variable with the URL of the CRM instance that you want to connect to (e.g., **Name**: *endpointURL* **Default**: *"https://uipath.crm4.dynamics.com/*" )
11. In the **TenantId** property, create and enter a `String` variable for the directory (tenant) ID assigned to your Azure Active Directory (ADD) tenant (e.g., **Name**: *tenantId* **Default**: *"d8353d2a-b153-4d17-8827-902cXXXXXXX"*).
    * If you selected *PasswordCredentials*, select your password **Prompt** preference ([options](https://docs.uipath.com/activities/other/latest/user-guide/microsoft-dynamics-365-scope)).

      ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-178119-8dc18e5b-af7bcd39.webp)
12. Add the [Insert Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-insert-record) activity inside the **Microsoft Dynamics Application Scope** activity.
    1. Click the **Configure** button inside the **Insert Record** activity (this opens the **Object Wizard**).
       1. In the **Select Entity** drop-down list, select *Account*.
       2. In the **accountId** field, create and enter a `String` variable (e.g., *accountId*).
       3. In the **Add Single Field** textbox, enter *name* and click enter.
       4. In the **name** field, enter an account name (e.g., *"Quickstart_Account"*).
       5. Click the **Done** button.

          ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-186934-16b52441-15348bf9.webp)
    2. Add an **Add to dictionary** activity after the **Insert Record** activity.
    3. In the **Dictionary** property, create and enter a `Dictionary<String,String>` variable accordingly: **Name**: *queryOption*, **Default**: *new Dictionary(Of String, String)* (you may use a different **Name** value, but the **Default** value is required).
    4. In the **Key** property, enter *"$filter"*.
    5. In the **Value** property, enter *"name eq 'Quickstart_Account'"* (*Quickstart_Account* is the name of the account you inserted in the steps above. If you entered a different name, use that value instead).
       * For more information about query values, see the [query metadata](https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/query-metadata-web-api) and/or [query data](https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/query-data-web-api) pages in the Microsoft documentation.
    6. Add the [Search Records](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-search-records) activity after the **Add to dictionary** activity.
    7. In the **Object** property, select *Account*.
    8. In the **Query Options** property, enter the `Dictionary<String,String>` variable you created above (e.g., *queryOption*).
    9. In the **Result** property, create and enter a `DataTable` variable (e.g., *searchResults*).

       ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-183289-1da5864a-93f7a301.webp)
13. Add an **Assign** activity after the **Search Records** activity.
    1. In the **To** property, create and enter a `String` variable (e.g., *webURL*).
    2. In the **Value** property, enter the following: *searchResults.Rows(0).Item("websiteurl").ToString*.
       * For more information about the column names for each entity, see the [Web API EntityType Reference](https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/entitytypes?view=dynamics-ce-odata-9) in the Microsoft documentation.
    3. Add an **If** activty after the **Assign** activity.
    4. Create a `String` variable with a default value of a URL (e.g., **Name**: *website*, **Default**: *"www.uipath.com"*).
    5. In the **Condition** property, enter the following: *webURL = website*.
    6. In the **Then** statement box, add a **Write Line** activity with the following **Text**: *"Website present"*.
    7. In the **Else** statement box, add the [Update Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-update-record) activity.
       1. Click the **Configure** button inside the **Update Record** activity (this opens the **Object Wizard**).
          1. In the **Select Entity** drop-down list, select *Account*.
          2. In the **accountId** field, enter the `String` variable you created for the **Insert Record** activity (e.g., *accountId*).
          3. In the **Add Single Field** textbox, enter *websiteurl* and click enter.
          4. In the **name** field, enter the `String` variable you created in the step above (e.g., *website*).
          5. Click the **Done** button.

             ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-180296-575a1711-249e1c52.webp)

### Test your project

1. Add the [Get Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-get-record) after the **Update Record** activity (inside the **Else** statement box).
   1. Click the **Configure** button inside the **Get Record** activity (this opens the **Object Wizard**).
      1. In the **Select Entity** drop-down list, select *Account*.
      2. In the **accountId** field, enter the `String` variable you created for the **Insert Record** activity (e.g., *accountId*).
      3. In the **Add Single Field** textbox, enter *websiteurl* and click enter.
      4. In the **websiteurl** field, create and enter a `String` variable (e.g., *websiteVerification*).
      5. Click the **Done** button.
   2. Add an **If** activity after the **Get Record** activity (inside the **Else** statement box).
   3. In the **Condition** property, enter the following: *website = websiteVerification*.
   4. In the **Then** statement box, add a **Write Line** activity with the following **Text**: *"Website update succeeded!"*.
   5. In the **Then** statement box, add a **Write Line** activity with the following **Text**: *"Website update failed"*.
2. Add the [Delete Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-delete-record) activity outside of the first **If** activity.
   1. In the **Object** property, select *Account*.
   2. In the **Id** field, enter the `String` variable you created for the **Insert Record** activity (e.g., *accountId*).
   3. In the **MicrosoftDynamicsStatus** property, create and enter a `ResponseStatus` variable (e.g., *responseStatus*).
3. Add a **Write Line** activity after the **Delete Record** activity.
   1. In the **Text** property, enter the following: *"Record deleted: "+responseStatus.Success.ToString*.
4. Click **Run** and verify the **Output** window includes the expected write line values.

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-180984-96a09b8d-083f13ea.webp)

You're done!

To learn more about the Microsoft Dynamics 365 activities (including example property inputs/outputs), see the [Activities](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-activities) page for a complete activity list and links to the activity detail pages.
