Category Archives: Dynamics 365 JavaScript

CI/CD & Test Automation for Dynamics 365 in Azure DevOps/VSTS -Part 5 – Master Data Deployment

In my previous blog, I wrote about how to set up a gated check-in, In this blog, we will see how to move the master data from source to target instance using our CI/CD pipeline.

Generally, we use the configuration migration tool to move the master data across multiple environments and organizations. Configuration data is used to define custom functionality in model-driven apps in Dynamics 365, such as Dynamics 365 Sales and Customer Service, and is typically stored in custom entities. Configuration data is different from end-user data (account, contacts, and so on). A typical example of configuration data is what you define in the Unified Service Desk for Dynamics 365 to configure a customized call center agent application. The Unified Service Desk entities, along with the configuration data that is stored in the entities, define an agent application.

Note: Disable plug-ins before exporting data and then re-enable them on the target system after the import is complete for all the entities or selected entities.

Master data/Configuration data deployment

undefinedDefine the schema of the source data to be exported: The schema file (.xml) contains information about the data that you want to export such as the entities, attributes, relationships, definition of the uniqueness of the data, and whether the plug-ins should be disabled before exporting the data.

undefinedUse the schema to export data: Use the schema file to export the data into a .zip file that contains the data and the schema of the exported data.

undefinedImport the exported data: Use the exported data (.zip file) to import into the target environment. The data import is done in multiple passes to first import the foundation data while queuing up the dependent data, and then import the dependent data in the subsequent passes to handle any data dependencies or linkages.

Instead of moving it manually we are going to automate this above process using Azure DevOps.


  • Please make sure the latest configuration.xml(generated using DataMigrationUtility.exe tool) is generated and placed in the desired input location.
  • Please make sure we have updated the variables (correct connection string, CRM username, CRM password) in both the VSTS build and release definition.               

VSTS Build Definition

We have to create a separate Build Definition for moving the master data from source to target instance. Once the solution movement is done this below build definition should trigger.

In my previous blog, I have explained how to create a new build definition. Please refer to that for creating a new build definition.

What will do – It will connect to the source instance and export the master data using the configuration.xml and push it to artifacts repository

In this Build Definition we have used the following MSCRM Build Tools tasks:

  • MSCRM Tool Installer – Installs the Dynamics 365 tools required by all of the tasks
  • MSCRM Export config migration data – Exports data from a CRM instance using a Configuration Migration schema file (How to prepare configuration schema file).

You have to update the connection string variable name and select the configuration.xml input location.

  • Publish build artifacts – Publish build artifacts to Azure Pipelines

Release Definition

Once the above definition gets succeded, this Release Definition will trigger automatically and performs the following tasks:

  • MSCRM Tool Installer – Installs the Dynamics 365 tools required by all of the tasks
  • MSCRM Import config migration data – Import data exported using Configuration Migration Tool into a CRM instance

You have to update the connection string variable name and select the exported data zip from the artifacts repository(drop).

This will import the master data/configuration data into our Dynamics Online sandbox instance.

In my next blog, we will see how to integrate the unit testing framework with the VSTS Build definition.

If you are interested in this topic and would like to do some further self-study I encourage you to check out my blog on this.

Dynamics 365 Set Parent Child relationship from Correct Sub grid (Relationship)

Let us consider we have two entities. Entity A (Parent entity) and Entity B (child entity). I have created two lookup of entity A in entity B. Now we will have two associated sub grids of Entity B in Entity A. Whenever I tried a new entity B record (child record) from entity A (parent record) using the associated sub grid add button, it’s auto populating both the lookup fields of entity A in entity B record.

For this scenario, the easiest way is just to remove the field mapping. But the problem is when you want to try to delete one of the mapping, CRM platform won’t allow us to do it. Error details are as follows:

Then the only way to achieve our scenario is by customization only and here are my steps to solve it:

It’s not always recommended to customize the OOB button. So, in this case we can achieve this scenario by adding a custom button.

Create a html resource using the below code:

<!DOCTYPE html>
 <html lang="en" xmlns="">
 <meta charset="utf-8" />
 <title>Entity B Record</title>
 .btnSubmit {
 background-color:rgba(0, 0, 0, 1) !important;
 height: 24px;
 font-family: Segoe UI;
 font-size: 12px;
 color: rgb(255,255,255);
 border: 1px solid rgba(0, 120, 215, 1.0);
 background-image: none;
 margin-top: 10px;
 width: auto !important;
 min-width: 80px;
 white-space: nowrap;
 function openEntityBRecord () {
 var recordId =;
 var fullName ="fullname").getValue();
 var entityFormOptions = {};
 entityFormOptions["entityName"] = "plc_associatedpriorityservice";
 entityFormOptions["openInNewWindow"] = true;
 var formParameters = {};
 formParameters["EntityA1id"] = recordId;
 formParameters["EntityA1name"] = fullName;
 Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
 function(success) {
 function(error) {
 <input style="float:right;" type="button" class="btnSubmit" id="btnSubmit" name="btnSubmit" value="Add Entity B Record" onclick="openEntityBRecord();">

Then go to form Editor of Entity A and insert a web resource just above the first associated sub grid. When finished, publish all customization and you can try the result.

Now the “Add Entity B Record” button will appear above the first associated sub grid in Entity A(parent) record.

Similar in the same way we need to do it for second associated sub grid.

Also, we need to hide the OOB Add button form both the sub grids by using the below code:

 var hideSubgridAddBtn = function(primaryEntityName) {
         if (primaryEntityName == “entityname”)
             return false;
             return true

Add the above method to the one JavaScript library and we need to add a enable rule to the OOB button and call the above method “hideSubgridAddBtn” from the above newly created JavaScript library.

Once done, publish all the customization and you can try the result. It will set only the first lookup of entity A in entity B record.