# Microsoft Dynamics Application Scope

> `UiPath.MicrosoftDynamics.Activities.MicrosoftDynamicsScopeActivity`

`UiPath.MicrosoftDynamics.Activities.MicrosoftDynamicsScopeActivity`

The Dynamics 365 activities use the [OAuth with Common Data Service](https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/authenticate-oauth) protocol to establish an authenticated connection between UiPath and your Dynamics 365 application. This connection authorizes a Robot to call the Web APIs and access resources on your behalf.

To enable authentication, you use the Azure Active Directory (AAD) to register your Dynamics 365 application in your account tenant. Registering your application generates an **Application (client) ID** that's used along with other identifiers to establish authenticated access to your instance. For more information and before you build your first automation project, see the [Setup](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-setup) guide.

After completing your application registration, you select the type of authentication that you want to use (**AuthenticationType**) and enter your Application (client) ID (**ClientId**), Dynamics 365 application endpoint (**EndpointUrl**), Directory (tenant) ID (**TenantId**), and depending on the authentication type that you select, your client secret (**ClientSecret**).

## How it works

The following steps and message sequence diagram is an example of how the activity works from design time (i.e., the activity dependencies and input/output properties) to run time.

1. Complete the [Setup](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-setup) steps.
2. Add a activity if your **AuthenticationType** is *ClientCredentials*, otherwise this is N/A.
   * For more information, see [Credential Management](https://docs.uipath.com/activities/other/latest/user-guide/integrations-credential-management) in this guide.
3. Add the **Microsoft Dynamics Application Scope** activity to your project.
4. Enter values for the [Connection](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-scope#microsoft-dynamics-application-scope) input properties.
5. Create and enter a `MicrosoftDynamicsConnection` variable for Output poperty.
   * You can use this variable in subsequent uses of the **Microsoft Dynamics Application Scope** activity.

     ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-182877-b0a8e5f6-decd42f0.webp)

## In the Body of the Activity

To build your project and enable the **Object Wizard** in other activities, you must use the **Connection Wizard** by clicking the **Configure** button.

To learn more about the **Connection Wizard**, see the [Business Activity Frameworks](https://docs.uipath.com/integrations/docs/business-activity-framework#connection-wizard) page.

:::note
Configuring the fields in the **Connection Wizard** does not populate the **Microsoft Dynamics Application Scope** properties. The wizard establishes a connection to your Microsoft Dynamics 365 application during design time only; enabling the **Object Wizards** in the other Microsoft Dynamics 365 activities.
:::

## Properties

### Common

* **DisplayName** - The display name of the activity. This field supports only `Strings` or `String` variables.

### Connection

* **AuthenticationType** - The type of authentication that you want to use to connect to your Dynamics 365 application. Select an item from the drop-down list. There are two options:
  + **PasswordCredentials** - If selected, authentication is done via a user prompt (according to the option that you select in the **Prompt** property) to enter the password to their Dynamics 365 account. This option is for attended automation only.
  + **ClientCredentials** - If selected, authentication is done via a **ClientSecret**. This option is for both attended and unattended automation. For more information about client credentials, see [Use Client Secrets & Certificates](https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/authenticate-oauth#use-client-secrets--certificates) in the Microsoft documentation.
* **ClientId** - The auto-generated, Application (client) ID assigned to your registered application. This field supports only `String` variables.
  + The **ClientId** gets generated when you register your application using the Azure Active Directory (AAD). For more information, see the [Register your application](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-setup) section of the **Setup** guide.
  + If your **AuthenticationType** value is *ClientCredentials*, the **ClientId** is associated with the **ClientSecret**. Becuase of this relationship, it's recommended that you create a `String` variable for this property by following the [Create Credential Asset](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-setup) section of the **Setup** guide.
  + To create and enter your `String` variable for this property, use a activity to output your Credential Asset (see [example](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-scope) below).
* **ClientSecret** - The password (associated with the **Username**) to your ServiceNow instance. Enter a `SecureString` variable.
  + The **ClientSecret** can be generated when you register your application using the Azure Active Directory (AAD). For more information, see the [Create client secret](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-setup) section of the **Setup** guide.
  + To create a `SecureString` variable, see the [Create Credential Asset](https://docs.uipath.com/activities/other/latest/legacy-integrations/microsoft-dynamics-365-setup) section of the **Setup** guide.
  + To enter your `SecureString` variable, use a activity that outputs your Credential Asset (see [example](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-scope) below).
* **EndpointUrl** - The URL of the CRM instance that you want to connect to. This field supports only `Strings` or `String` variables.
* **Prompt** - Specifies the password prompt behavior for the **PasswordCredentials** authentication. Select an item from the drop-down list. There are three options:
  + **Auto** - The prompt only appears when credentials are necessary.
  + **SelectAccount** - The prompt requires a user to select an account and then enter their credentials (used when there are multiple accounts).
  + **Always** - The prompt appears each time the activity is run (even when there is a token in the cache).
* **TenantId** - The Directory (tenant) ID assigned to your Azure Active Directory (ADD) tenant. This field supports only `Strings` or `String` variables.

### Existing Connection

* **ExistingMicrosoftDynamicsConnection** - A connection record from a parent **Microsoft Dynamics Application Scope** activity that you can use instead of establishing a new connection. Enter a `MicrosoftDynamicsConnection` variable.
  + The `MicrosoftDynamicsConnection` variable must be from a previously run **Microsoft Dynamics Application Scope** activity (parent) that still has an active connection.
  + If you're unable to establish a connection using this property, try re-running your parent **Microsoft Dynamics Application Scope** activity.

### Misc

* **Private** - If selected, the values of variables and arguments are no longer logged at Verbose level.

### Options

* **ReportApiErrorAsException** - When selected, API error responses are reported in BusinessActivityExecutionException by all child activities that use this application scope. When cleared, the child activity populates the API error message in the ResponseStatus output property and workflow execution continues. Check the ResponseStatus property to confirm successful execution.

### Output

* **MicrosoftDynamicsConnection** - A record of your established connection that you can use in other **Microsoft Dynamics Application Scope** activities that are included in this scope activity. Enter a `MicrosoftDynamicsConnection` variable. You can pass this variable to a scope activity in a workflow that is from within the parent scope activity.
  + For example, you may have 3 workflows. The first includes the parent scope activity that establishes the connection to your registered application (i.e., parent workflow). The second workflow creates a new contact record and the third creates a new account record; both are included in the parent scope activity.
  + When the workflows run, the parent scope activity passes the`MicrosoftDynamicsConnection` variable to the **ExistingMicrosoftDynamicsConnection** property in the second and third workflows (see image below).

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-183749-859f3a0f-5909e82a.webp)

## Example

The following image shows an example of the activity dependency relationship and input/output property values.

![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-187102-58c510f8-09a3d77d.webp)
