This article shows how to retrieve a User ID from a different Dynamics 365 instance using Azure.
North52 Decision Suite
The North52 Decision Suite solution works like this:
- A formula is created that will trigger whenever a workflow activates it
- The formula will gather the Azure token using its directory(tenant id), client_id and client_secret
- The formula will then use this token to retrieve this userid using a CallRestAPI
Setup - Create App
- Navigate to portal.azure.com and login to your Azure instance
- Click on Azure Active Directory in the blade
- Click on App Registration
- Click New registration
- Give the App a name and leave everything else default.
- In this example we called it North52TestApp
- Click Register
- From the Overview section make note of the Application ID and the Directory (Tenant) ID
Setup - Create Secret in App
- From the App you created above, navigate to Certificates & Secrets
- Click New Client Secret
- Give it a Description and set its expiry date.
- In this example we called it North52TestAppSecret
- Click Add
- Copy the Value of the secret and save it for later
Setup - Grant Permission in App
From inside your Azure App:
- Click API Permissions
- Click Add a permission
- Select Dynamics 365
- Tick user_impersonation
- Click Add permissions
- Click Grant admin consent for your company name
- Navigate to Settings > N52 Formula
- Create a new formula, setting the following values in the Formula Guide:
- Source Entity set to Account
- Set Formula Type to Clientside Calculation
- Select the Classic editor
- Change the Name of the formula to Retrieve Userid from a different CRM Instance using Azure
- Copy and paste the following into the Classic editor
- (Note: you will need to change the parameters to match yours, 6e50330d-7376-4348-aacb-xxxxxxxxxxxx is your Directory (tenant) ID )
smartflow( SetVar('token', azureadgettoken('6e50330d-7376-4348-aacb-xxxxxxxxxxxx', SetRequestParams('resource', 'https://xxxxxxx.api.crm4.dynamics.com', 'username', 'email@example.com', 'password', 'xxxPasswordxxxx', 'client_id', '017c67b7-b07b-4c6f-bd26-xxxxxxxxxxx', 'client_secret', 'I:mH%xxxxxxxx;FOf', 'grant_type', 'password'))), CallRestAPI( SetRequestBaseURL('https://xxxxxxxxx.api.crm4.dynamics.com/api/data/v8.2'), SetRequestResource('/WhoAmI()'), SetRequestDetails('GET'), SetRequestHeaders('Authorization', 'Bearer ' + GetVar('token'), 'Content-Type', 'application/json; charset=utf-8', 'Accept', 'application/json', 'Data-MaxVersion', '4.0', 'OData-Version', '4.0'), SetRequestParams(), SetRequestAuthenticationNone(), SetRequestFiles(), SetRequestExpected('Ok'), 'NoOp', 'NoOp') , GetVarJsonValue('UserId') )
- Click Save
Within the Formula editor click the lightning bolt button on the right hand side and click Execute. You will see the Guid of the User like below.
Note: Ignore any prompts for input you may get like below, click Execute.
Did you know?
North52's Decision Suite can help enhance Dynamics Business Process Flows
Sometimes business processes are more complicated and have significant permutations that are not easily managed with the out-of-the-box Business Process Flow (BPF) functionality. With North52 Decision Tables you can create rule dependent task checklists for each BPF stage and not allow users to progress until your rule criteria has been met.