Skip to main content
Dynamics 365 general forum
Suggested answer

Unable to Customize Add Existing Button in the subgrid in UCI In Dynamics 365 CRM with 9.1 version.

editSubscribe (0) ShareShare
ReportReport
Posted on by 5

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);
    }
}

Attachments
  • Suggested answer
    Henry J. Profile Picture
    Henry J. 5,235 on at
    RE: Unable to Customize Add Existing Button in the subgrid in UCI In Dynamics 365 CRM with 9.1 version.

    Hello Jincy,

    The code you shared contains a number of unsupported and undocumented methods, which is something Microsoft has always advised against:

    • Mscrm.GridRibbonActions.addExistingFromSubGridStandard
    • XrmCore.Commands.AddFromSubGrid.addExistingFromSubGridAssociated

    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

Helpful resources

Quick Links

New Blog Features Released!

Check out the new community blog features for viewers and authors…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,080 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,601 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Featured topics

Product updates

Dynamics 365 release plans