Monthly Archives: May 2019

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.