web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

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

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

I have the same question (0)
  • Suggested answer
    Henry J. Profile Picture
    5,237 on at

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 150

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 65 Super User 2026 Season 1

#3
ManoVerse Profile Picture

ManoVerse 53 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans