General Discussion

Tech Talk: Implementation – Dynamics 365 Field Service Integration Part 1 (also Dataverse)

  • 1.  Tech Talk: Implementation – Dynamics 365 Field Service Integration Part 1 (also Dataverse)

    Posted 12 days ago
    Edited by Ian Chamberlain 12 days ago

    Today I am going to be talking about an integration into Dynamics 365 which is a Product that is built on top of Microsoft Dataverse Tables. All of Microsoft's products will typically use OData to query data. This might introduce some new concepts if you have never used a service that supports OData but just know that it is a different way to query data through a REST API.  

    This is a lengthy topic, so I am going to be splitting this post into 2 posts to make it a little more bite sized. In this post, I am going to talk about creating the Connection and how you can pull your data into TrueContext. The next post will cover pushing data back into Microsoft.  

    If you use Dynamics/Dataverse, you are likely used to this terminology, but I wanted to call out that when you are using OData to query there are some differences. 

    Entity: An entity is like an Object in Salesforce. In Dataverse, an entity will refer to a table. This would be a Case or Account.  

    While you are building this all out, I would HIGHLY suggest starting off in Postman or Insomnia to ensure that you are getting the expected results prior to implementing it in TrueContext. To get started, you can follow this guide 

     

    Creating the connection 

    Since this is not an out of the box connector, we will be leaning heavily on the HTTP Connection to perform GETs and POSTs.  
    All of the information that you need can be found at this link. These are just suggestions to set up the app, there are always going to be permissions to consider when setting this up. 

    1. Create a new App Registration here: https://portal.azure.com/ 

    1. Search for App Registrations in the Services Search bar 

    1. Click on New Registration 

    1. Give it a name and then click Register at the bottom. 

    1. Once the registration is complete, go to the "Certificates and Secrets" tab  

    1. Create a new Secret and copy the Secret Value (not the ID) and save it for later. Once the secret becomes hidden, you cannot retrieve the value and will need to create a new one if needed. 

    1. Next go to the API Permissions tab, add a new permission.  

    1. Move to the "APIs my organization uses" and search for Dataverse. 

    1. Add in the user_impersonation permission for Dataverse. 

     

    The next step will be to assign this new App Registration to the Dataverse (Dynamics) environment.  

    1. Go to Environments, and click into your Dynamics Environment 

    1. Click on Settings, expand 'Users + Permissions' and click on 'Application Users' 

    1. Click "New App User" 

    1. Click on the + and specify the App that we just created above.  

    1. Under Business Unit, you will put in the beginning part of the Dynamics URI. Only the Unique ID of it, this is a dropdown field but does not always show you the available options so you might need to type it out.  

    1. Assign the right Security Roles. The bare minimum is "Basic User", or everything would be "System Administrator" 

     

    Create a new Connection in TrueContext with the HTTP Connection using the following settings and the information from your app that was just created. 

    1. Grant Type: Client Credentials 

    1. Access Token URL: https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/token 

    1. Client ID: ID from the app created above. Also known as the Application ID. 

    1. Client Secret: The Secret Value (not the ID) that was created in your app 

    1. Base Connection URL: https://<org>.crm3.dynamics.com/ 

    1. Scopes: https://<org>.crm3.dynamics.com/.default 

     

    Change the <tenant> to the tenant where your app is registered and the <org> will refer to your Dynamics Environment URL, you will also have one of these if you are not using Dynamics and just using the Dataverse tables. 

    Click Connect in the Connection and you should see a Connection Established and the connection is ready to be used! 

    Create a Data Source 

    Data Sources in TrueContext are created using the HTTP GET Data Source. The Web API employs the OData protocol to interface with tables in Dataverse, allowing us to use the same OData functionality across any table in Dynamics/Dataverse. 

    When initially building your data sources, it is highly recommended to experiment with them in Postman or Insomnia before integrating them into TrueContext 

    The primary consideration should be identifying the necessary information for your form. Your data sources should not include all columns from a particular entity. 

    The endpoints for retrieving data are consistent across all entities. There are two main methods to find the entity name:  

    1. Open Dynamics in your browser, navigate to the desired entity, and examine the URL. The parameter 'etn=' in the URL shows the entity name. Note that some names are more intuitive than others (e.g., 'contact' for Contact, but 'incident' for Case), so always verify the URL. 

    1. With OData, you can use the $select parameter to retrieve only the specific columns needed. This will be included in the Query-String Arguments in TrueContext. 

    In this example, I am going to GET all the contacts from Dynamics (using the connection we created in the earlier step) 

    1. URL Path: api/data/v9.2/contacts (contacts can be changed to whatever entity you would like to pull) 

    1. Query String Arguments (this is where you can define OData Arguments to refine your GET) 
      Key: $select 
      Value: emailaddress1,address1_composite,yomifullname,contactid,jobtitle,_parentcustomerid_value,mobilephone 

    1. Click Save at the bottom and the Data Source should go out and fetch all the specified data 


    In the next post, I am going to cover writing all the collected data back into Dynamics, both with a
    regular POST call and how we can use the $batch endpoint to accommodate more complex workflows all in a single request using
    FreeMarker. If you've done any integrations with Dataverse/Dynamics before, let us know how that went for you and if you found any cool tips and tricks along the way! 

    #TechTalkImplementation #Dynamics365 #Microsoft



    ------------------------------
    Ian Chamberlain
    Solutions Architect
    TrueContext
    ------------------------------



Reminder: Content posted to our Community is public content.  Please be careful not to post Intellectual Property that you do not have permission to share.  For more information please refer to our Terms Of Use