Hi,
I have some custom entities and need to customize the Add Existing Button in the subgrid based on the values provided in the fields added in the main entity.
I tried to do with below code and it throws error saying that getRelationship() is not a function.
Kindly provide a solution to overcome this issue.
// JavaScript source code function replaceAddExistingButtonViewCustom(gridTypeCode, gridControl, primaryEntityName, primaryEntityTypeCode, firstPrimaryItemId, gridTypeName, PrimaryControl) { if (primaryEntityName == "md_postsalestransactionheader") { var contactId = Xrm.Page.getAttribute("md_customercontact").getValue()[0].id; var picklistType = "md_type"; var picklistTypeName = Xrm.Page.getControl(picklistType); var picklistTypeAttribute = picklistTypeName.getAttribute(); var picklistTypeSelectedOption = picklistTypeAttribute.getSelectedOption(); var unitSaleIDs = ""; } if ((primaryEntityName == "md_postsalestransactionheader") && (picklistTypeSelectedOption.text == "Fund Transfer") && (gridTypeName == "md_receipt")) { // AssociateReceipts(PrimaryControl); //Code commented as it throw error. var PropertyId = new Array(); var ContactId = new Array(); var AccountId = new Array(); var UnitSaleID = new Array(); var UnitID = new Array(); var Conditions = ""; var LinkEntityConditions = ""; var status; if (Xrm.Page.getAttribute("md_receiptcontactid").getValue() != null) { ContactId = Xrm.Page.getAttribute("md_receiptcontactid").getValue()[0].id; Conditions = ""; } if (Xrm.Page.getAttribute("md_receiptaccountid").getValue() != null) { AccountId = Xrm.Page.getAttribute("md_receiptaccountid").getValue()[0].id; Conditions = ""; } if (ContactId != null || AccountId != null ) { replaceAddExistingButtonView({ gridTypeCode: gridTypeCode, gridControl: gridControl, primaryEntityTypeCode: primaryEntityTypeCode, primaryItemId: firstPrimaryItemId, fetchXml: "" " " " " " " " " " " " " " " " " " 100000000" " 1" " " Conditions " " "", layoutXml: "" "" "" "" "" "" "" "" "" "" "" "", name: "Receipts.", context: this }); } else { } } else { Mscrm.GridRibbonActions.addExistingFromSubGridStandard(gridTypeCode, gridControl); } } function replaceAddExistingButtonView(selectedEntityTypeName, selectedControl, firstPrimaryItemId) { if (selectedControl.getRelationship().name === "md_md_postsalestransactionheader_fundtransfe") { var options = { allowMultiSelect: true, entityTypes: ["md_receipt"], showNew: true, customFilterTypes: [""], customFilters: [encodeURIComponent("")] }; lookupAddExistingRecords("md_md_postsalestransactionheader_fundtransfe", "md_postsalestransactionheader", "md_receipt", firstPrimaryItemId, selectedControl, options); } else { XrmCore.Commands.AddFromSubGrid.addExistingFromSubGridAssociated(selectedEntityTypeName, selectedControl); } }