Skip to main content

Notifications

Announcements

No record found.

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

  • Suggested answer
    Henry J. Profile Picture
    5,237 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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,025 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,837 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans