{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":21537,"path":"integrate-applications/integration-hub/setup-ms-dynamics-crm.md","title":"Set up Microsoft Dynamics CRM spoke","bundle":null,"doc_type":null,"release":"australia","body":"\n# Set up Microsoft Dynamics CRM spoke\n\nIntegrate the ServiceNow instance and Microsoft Dynamics CRM by using the Windows credentials to authenticate ServiceNow requests.\n\n## Before you begin\n\n-   Request Integration Hub subscription.\n-   Install Microsoft AD.\n-   Activate the Microsoft Dynamics CRM spoke.\n-   Role required: admin.\n\n## About this task\n\nPerform these steps to use all Microsoft Dynamics CRM spoke actions.\n\n## Configure Microsoft Dynamics CRM application\n\nCreate a custom OAuth application from your Microsoft Dynamics CRM account to enable OAuth 2.0 authentication with the Microsoft Dynamics CRM.\n\n### Before you begin\n\nMicrosoft Dynamics CRM requirements:\n\n-   Microsoft Dynamics CRM account\n-   [Microsoft Azure](https://portal.azure.com) account\n-   Role required: Microsoft Dynamics CRM admin\n\n### About this task\n\nComplete these steps from your Azure Developer account. See the [Azure](https://docs.microsoft.com/en-us/azure/) product documentation for instructions on creating and configuring custom applications.\n\n### Procedure\n\n1.  Log in to the [Microsoft Azure App registration portal](https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade) with your organization credentials.\n\n2.  Register a new custom application by filling in the application name, the supported account type, and the redirect URI, and then click **Register**.\n\n    An overview of the application's basic information is shown.\n\n3.  Copy the application ID to a text file.\n\n    You will use this ID and the client secret generated in the next step to register the app as a third-party OAuth provider on your ServiceNow instance. You use the application ID as the client ID when you connect the application to ServiceNow.\n\n4.  Add a client secret.\n\n    1.  In Microsoft Azure, navigate to **Manage** &gt; **Certificates &amp; secrets**.\n\n    2.  Provide a description and an expiration date and click **Add**.\n\n        **Note:** The client secret is only displayed in plain text for a short time. You use the client secret when you connect the application to ServiceNow.\n\n5.  Enable the permissions you want the application to support.\n\n    For more information, see the [Microsoft Graph permissions reference](https://docs.microsoft.com/en-us/graph/permissions-reference).\n\n    1.  In Microsoft Azure, navigate to **Manage** &gt; **API permissions**.\n\n    2.  Click the Microsoft Graph tile.\n\n    3.  Select the Delegated or Application permissions that the application supports.\n\n        Delegated permissions enable the application to access the API as a signed-in user. Application permissions enable the application to run as a background service or daemon without a signed-in user.\n\n    4.  Click **Add permissions**.\n\n\n### What to do next\n\n[Register Microsoft Dynamics CRM as OAuth provider](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/integrate-applications/integration-hub/setup-ms-dynamics-crm.md).\n\n## Register Microsoft Dynamics CRM as OAuth provider\n\nUse the information generated during Microsoft Dynamics CRM account configuration to register Microsoft Dynamics CRM as an OAuth provider and allow the instance to request OAuth 2.0 tokens.\n\n### Before you begin\n\n-   Request Integration Hub subscription.\n-   Activate Microsoft Dynamics CRM.\n-   Create a Microsoft Dynamics CRM application.\n-   Role required: admin.\n\n### Procedure\n\n1.  In ServiceNow, navigate to **System OAuth** &gt; **Application Registry**.\n\n2.  Click **New**.\n\n3.  On the screen titled **What kind of OAuth application**, select **Connect to a third-party OAuth Provider**.\n\n4.  On the form, fill in the fields.\n\n    |Field|Value required|\n    |-----|--------------|\n    |Name|Enter any name to uniquely identify the record, for example `Dynamics CRM OAuth profile`.|\n    |Client ID|Enter the Application ID of the Microsoft Dynamics CRM application you created in Azure.|\n    |Client Secret|Enter the Client Secret you generated when you created the application in Azure.|\n    |Default Grant type|Select **Authorization Code**.|\n    |Authorization URL|Click the lock icon \\(\\[Omitted image \"icon-lock.png\"\\] Alt text: Lock icon\\), enter `https://login.microsoftonline.com/common/oauth2/v2.0/authorize` followed by a question mark and the resource attribute of your instance, and then click the lock icon again. The resource attribute of the URL. For example, `?resource=https://mycompany.crm.dynamics.com`. This attribute is the URL of your Microsoft application.|\n    |Token URL|Click the lock icon \\(\\[Omitted image \"icon-lock.png\"\\] Alt text: Lock icon\\), enter `https://login.microsoftonline.com/common/oauth2/v2.0/token`, and then click the lock icon again.|\n    |Redirect URL|Click the lock icon \\(\\[Omitted image \"icon-lock.png\"\\] Alt text: Lock icon\\), enter `https://<instance>.service-now.com/oauth_redirect.do`, and then click the lock icon again.|\n\n5.  In the **OAuth Entity Scopes** related list, edit the provided entity scope to include the URL of your Microsoft Dynamics CRM application.\n\n    The name and the OAuth scope are often the same string.\n\n    \\[Omitted image \"oauth-entity-scopes-ms-dyn-crm.png\"\\] Alt text: The Microsoft Dynamics CRM OAuth entity scopes.\n\n6.  Right-click the form header, and click **Save**.\n\n    The system validates the OAuth credentials.\n\n\n### What to do next\n\nCreate credential record for Microsoft Dynamics CRM.\n\n## Create Credential records for the Microsoft Dynamics CRM spoke\n\nCreate Credential records for the Microsoft Dynamics CRM custom OAuth application you created during Microsoft Dynamics CRM account configuration. The Microsoft Dynamics CRM spoke connection and credential aliases use these credentials to authorize actions.\n\n### Before you begin\n\nRole required: admin.\n\n### Procedure\n\n1.  Navigate to **All** &gt; **Connections &amp; Credentials** &gt; **Credentials**.\n\n2.  Click **New**.\n\n    The system displays the message **What type of Credentials would you like to create?**.\n\n3.  Select **OAuth 2.0 Credentials**.\n\n    The pop-up window displays a blank OAuth 2.0 Credentials form.\n\n4.  Enter these values.\n\n    |Field|Value required|\n    |-----|--------------|\n    |Name|Enter any name to uniquely identify the record. For example, enter `Dynamics Credentials`.|\n    |Active|Enable|\n    |OAuth Entity Profile|Select the OAuth profile you created when you registered the custom Microsoft Dynamics CRM application as an OAuth provider. For example, select **Dynamics OAuth profile**.|\n    |Order|Select the order to apply this credential. For example, enter `100`.|\n\n5.  Save the record.\n\n6.  From Related Links, click **Get OAuth Token**.\n\n    The system displays a confirmation message that the OAuth token flow is completed successfully. Review the details if the flow is not completed successfully.\n\n    **Note:** Ensure that you allow pop-up windows in your browser.\n\n\n## Create Connection records for the Microsoft Dynamics CRM spoke\n\nCreate Connection records to your Microsoft Azure account. The Microsoft Dynamics CRM spoke connection and credential alias uses these connections to perform actions on Microsoft Dynamics CRM.\n\n### Before you begin\n\nRole required: admin.\n\n### Procedure\n\n1.  Navigate to **All** &gt; **Connections &amp; Credentials** &gt; **Connection &amp; Credential Aliases**.\n\n2.  Open the connection and credential alias for the Microsoft Dynamics CRM application.\n\n3.  On the **Connections** tab, click **New**.\n\n    The system displays a blank **HTTP\\(s\\) Connection** form.\n\n4.  Enter these values.\n\n    |Field|Value required|\n    |-----|--------------|\n    |Name|Enter any name to uniquely identify the connection record. For example, enter `MS Dynamics CRM Connection`.|\n    |Credential|Select the Credential record you created for Microsoft Dynamics CRM. For example, select **MS Dynamics Credentials**.|\n    |Connection alias|Select the Connection alias record you created for Microsoft Dynamics CRM.|\n    |Active|Enable|\n    |Connection URL|Enter the root Dynamics URL. For example, `https://<SiteName>.dynamics.com`.|\n\n5.  Click **Submit**.\n\n\n## Configure Microsoft Dynamics CRM webhook details\n\nRegister Microsoft Dynamics CRM webhook in ServiceNow to notify the ServiceNow application when certain events occur in Microsoft Dynamics CRM.\n\n### Before you begin\n\nRole required: admin\n\n-   Microsoft Dynamics CRM requires registration through the Windows Plugin Registration Tool. To install the Windows Plugin Registration Tool, see the Microsoft document [Download tools from NuGet](https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/download-tools-nuget).\n-   The Endpoint URL is the ServiceNow instance URL to which event information is posted. For example, `https://<instance-name>.service-now.com/api/sn_ms_crm_spoke/dynamics_webhook_callbacks`.\n-   The key-value pair you use to register the webhook in the Plugin Registration Tool is the same as the Name and Authorization Key in Dynamics CRM Webhook Details.\n\n### Procedure\n\n1.  Navigate to **All** &gt; **Dynamics CRM Webhook Details** &gt; **Client Details**.\n\n2.  Click **New**.\n\n3.  In the **Name** field, enter the webhook's plugin key.\n\n4.  In the **Authorization Key** field, enter the value from the webhook's key-value pair.\n\n\n### Configure Microsoft Dynamics CRM webhook decision policy\n\nCreate webhook routing policy and subflow according to your requirements.\n\n#### Before you begin\n\nRole required: admin.\n\n#### Procedure\n\n1.  Navigate to **All** &gt; **Flow Designer** &gt; **Designer**\n\n2.  Click **Subflows**.\n\n3.  Create a copy of the default sample subflow, Process Dynamics CRM Webhook.\n\n4.  Customize the subflow according to your requirement and publish it.\n\n    See [Create a subflow in Workflow Studio](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/build-workflows/create-subflow.md) for more information about creating and using subflows.\n\n5.  Navigate to **Dynamics CRM Webhook Details** &gt; **Decision Policy**.\n\n6.  On the **Decisions** tab, click **New**.\n\n7.  On the form, fill in the fields.\n\n<table id=\"table_awj_xgv_z3b\"><thead><tr><th>\n\nField\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nLabel\n\n</td><td>\n\nUnique label to identify the routing policy.\n\n</td></tr><tr><td>\n\nAnswer\n\n</td><td>\n\nOption to specify if this answer is the default answer. Default answer is applicable when the conditions are not met.1.  Click the Lookup icon.\n2.  Select the required subflow from the **Document:** list.\n\n**Note:** Ensure that the **Table name** is `Dynamics CRM Webhook Answer Subflow [sn_ms_crm_spoke_dynamic_crm_webhook_answer_subflow]`.\n\n</td></tr><tr><td>\n\nCondition\n\n</td><td>\n\nConditions to be met when the required events occur in Microsoft Dynamics CRM.\n\n</td></tr></tbody>\n</table>8.  Click **Submit**.\n\n    **Note:** These routing policies are saved in the Decision tables. Users are cautioned against directly updating or modifying data in these tables.\n\n\n#### Result\n\nDecision policy and subflow are created.\n\n"}}