====== Microsoft Dynamics CRM Integration ======
Microsoft Dynamics provides the following applications:
- Enterprise Resource Planning (ERP)
- Customer Relationship Management (CRM)
We are going to make use of CRM to fetch and update all the user details in Learnexa. CRM fundamentals include:
- Centralize customer information
- Provide business intelligence
- Analyze data
- Enable responsive customer service
===== Workflow Diagram =====
{{:workflow_diagram1.png}}
===== Create an account in MS Dynamics CRM =====
- Visit the following site and sign up a free trail https://www.microsoft.com/en-us/dynamics/free-crm-trial.aspx
- This will create a site with the organization name provided during free trial setup
- Free trial site created for test purpose:
- Organization URI: https://testdynamics3650.crm8.dynamics.com
- Username: yamini@testdynamics3650.onmicrosoft.com
===== Query CRM with Web API calls =====
=== Authenticate API via ADAL(Azure Active Directory Library) ===
- Sign up in https://azure.microsoft.com/en-in/pricing/free-trial/.
- Create an app under Azure Active Directory, which will provide client id and authorisation server tenant
- Steps to create an azure account and register an app are provided in this link: https://debajmecrm.com/2016/02/23/understanding-in-depth-cross-origin-resource-sharing-cors-in-dynamics-crm-2016/
- Make an API call to https://login.windows.net/common providing the Organization UI and client ID, which will return an access token that can be used for other API calls
resource: https://testdynamics3650.crm8.dynamics.com
clientId: d0835aea-3d68-462f-91a7-38edbbe4ab6f
tenant: crmdynamicsad.onmicrosoft.com
redirectUrl: http://localhost:3000/dynamics_crm/authenticate
request url: https://login.windows.net/crmdynamicsad.onmicrosoft.com/oauth2/authorize or (https://login.windows.net/common)
response: {"access_token":"token value encrypted"}
=== Retrieves specific user data using email ===
**Request**
GET [Organization URI]/api/data/v8.2/systemusers?$filter=contains(internalemailaddress,'davids@crmdemo.dynamics.com') HTTP/1.1
Authorization: "Bearer "
Accept: application/json
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0
**Response**
{
"@odata.context":"https://testdynamics3650.crm8.dynamics.com/api/data/v8.2/$metadata#systemusers/$entity","@odata.etag":"W/\"987803\"","systemuserid":"9025bbf4-3430-4d0c-bfcf-16f0bf7fbc80","accessmode":0,
"firstname":"David","address2_shippingmethodcode":1,"issyncwithdirectory":false,"address1_addressid":"420fc494-f768-4e49-b50e-f16a5b4c2fbd","incomingemaildeliverymethod":2,
"internalemailaddress":"davids@crmdemo.dynamics.com","domainname":"administration_5@crmdemo.dynamics.com","_queueid_value":"632476fd-32d9-e611-8119-c4346bdc3cc1",
"isintegrationuser":false,"createdon":"2017-01-13T01:52:51Z","_calendarid_value":"01fbd78c-61f2-4ca3-bb46-245d82e7b086","windowsliveid":"administration_5@crmdemo.dynamics.com",
"address1_addresstypecode":1,"_businessunitid_value":"85bf39cf-2bd9-e611-8119-c4346bdc3cc1","displayinserviceviews":false,
"defaultodbfoldername":"CRM","caltype":0,"modifiedon":"2017-01-19T06:20:59Z","address1_shippingmethodcode":1,"defaultfilterspopulated":false,
"outgoingemaildeliverymethod":2,"address1_composite":"US","emailrouteraccessapproval":2,"versionnumber":987803,"address2_addresstypecode":1,
"preferredphonecode":1,"fullname":"David So (Sample Data)","setupuser":false,"preferredemailcode":1,"userlicensetype":3,
"_modifiedby_value":"60ebc0f7-6bb0-49fa-9156-6c14b0eff61d","organizationid":"29f9e343-0e12-4d21-a7ec-455afe88b257","lastname":"So (Sample Data)",
"isemailaddressapprovedbyo365admin":false,"invitestatuscode":0,"yomifullname":"David So (Sample Data)","isdisabled":true,
"address2_addressid":"40284624-7726-4be5-83dc-55e7bb0317ea","_defaultmailbox_value":"622476fd-32d9-e611-8119-c4346bdc3cc1",
"address1_country":"US","preferredaddresscode":1,"islicensed":true,"ownerid":"9025bbf4-3430-4d0c-bfcf-16f0bf7fbc80","_createdby_value":null,
"nickname":null,"azureactivedirectoryobjectid":null,"address2_stateorprovince":null,"applicationiduri":null,"address1_county":null,
"address2_country":null,"address2_postofficebox":null,"yammeruserid":null,"title":null,"employeeid":null,"_territoryid_value":null,"jobtitle":null,
"skills":null,"address2_composite":null,"address1_postalcode":null,"entityimage":null,"address1_line3":null,"disabledreason":null,
"address2_utcoffset":null,"address1_line2":null,"address1_city":null,"personalemailaddress":null,"address1_telephone2":null,"_createdonbehalfby_value":null,
"address1_longitude":null,"sharepointemailaddress":null,"yomifirstname":null,"exchangerate":null,"yomimiddlename":null,"address2_line2":null,
"address1_line1":null,"address1_telephone1":null,"traversedpath":null,"yomilastname":null,"address2_latitude":null,"mobilephone":null,
"address2_fax":null,"address1_latitude":null,"entityimage_timestamp":null,"photourl":null,"_siteid_value":null,
"_transactioncurrencyid_value":null,"passportlo":null,"_mobileofflineprofileid_value":null,"address1_name":null,"address2_telephone2":null,
"_parentsystemuserid_value":null,"stageid":null,"address2_longitude":null,"salutation":null,"yammeremailaddress":null,"address2_city":null,
"middlename":null,"entityimageid":null,"address2_county":null,"address2_line1":null,"address2_upszone":null,"address1_utcoffset":null,
"_positionid_value":null,"passporthi":null,"address1_telephone3":null,"address2_postalcode":null,"address2_telephone1":null,"entityimage_url":null,
"processid":null,"governmentid":null,"_modifiedonbehalfby_value":null,"address2_line3":null,"utcconversiontimezonecode":null,
"homephone":null,"address2_name":null,"overriddencreatedon":null,"address1_upszone":null,"importsequencenumber":null,"mobilealertemail":null,
"address1_fax":null,"address2_telephone3":null,"address1_postofficebox":null,"address1_stateorprovince":null,"timezoneruleversionnumber":null,
"applicationid":null
}
=== Process the json response ===
- After the API call returns the json response, process it
- Update the Learnexa User table with the relevant data retrived from the CRM
===== Integrating Ms Dynamics CRM to Learnexa =====
- Create a new page in Manage site as "Integrate Dynamics CRM" with a form to enter CRM organisation URI, azure tenant ID, client ID provided in the Azure AD
- Once the form is submitted invoke a Delayed Job to update all the user records in Learnexa User Table by getting details from CRM
- On timely(every week/month) bases we can invoke the job again and again to update the user details that are changed in the CRM
=== Database ===
Create a new table to store MS dynamics CRM details:
**dynamics_crm_settings**
|ID|integer|
|company_id|integer|
|organization_uri|string|
|tenant_id|string|
|client_id|string|
**users**
|created_source|string|
===== References =====
- https://msdn.microsoft.com/en-us/library/mt593051.aspx
- https://msdn.microsoft.com/en-us/library/gg327838.aspx
- https://msdn.microsoft.com/en-us/library/mt770366.aspx
- https://msdn.microsoft.com/en-us/library/mt770367.aspx