
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);
}
} Hello Jincy,
The code you shared contains a number of unsupported and undocumented methods, which is something Microsoft has always advised against:
It is in fact expected that they can break without notice, especially during an update or transition to the Unified Interface.
While these might have technically worked in the legacy web client, I suppose they don't anymore in the Unified Interface.
You will find out more about unsupported customizations in this article:
https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/supported-customizations#unsupported-customizations
I suggest that you run the Solution Checker against your solutions to help you identify unsupported customizations and problematic patterns:
https://docs.microsoft.com/en-us/powerapps/maker/common-data-service/use-powerapps-checker
I don't believe there is a supported way for you to alter the behavior of the "Add Existing" button in a supported manner, but there are alternatives that you could investigate to meet your business requirements:
Henry