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 CRM (Archived)

Filter Subgrid : Cannot read property 'SetParameter' of undefined

(0) ShareShare
ReportReport
Posted on by 165

Hi, I'm working on Dynamics CRM 2016 (8.1) on premise, and I'm trying to filter a subgrid on onload form event via fetch xml, but I get this error

My function is:

function filterSubGridsRegBonus() {
    filterSubGrid("Subgrid_1");
    filterSubGrid("Subgrid_2");
}

function filterSubGrid(subgridName) {
    var formContext = Xrm.Page;

    var entityId = formContext.data.entity.getId().replace('{', '').replace('}', '');
    var entityName = formContext.getControl("EntityName").getEntityName();

    var subgrid = window.parent.document.getElementById(subgridName);

    if (subgrid == null) {
        setTimeout(function () {
            filterSubGrid();
        }, 2000);
        return;
    }

    var fetchXml =
        "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
        "<entity name='" + entityName + "' >" +
        "<all-attributes/>" +
        "<filter type='and' >" +
        "<condition attribute='param1' operator='neq' value='" + entityId + "' />" +
        "</filter>" +
        "<filter type='and' >" +
        "<condition attribute='param2' operator='neq' value='" + entityId + "' />" +
        "</filter>" +
        "</entity>" +
        "</fetch>";

        subgrid.control.SetParameter("fetchXml", fetchXml);
        subgrid.control.refresh();
}


How can I solve this? Thank you!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Kalpavruksh D365 CoE Profile Picture
    2,545 on at

    Hi,

    Please try below code: 

         function FilterCasesSubgrid() {

        //var CasesSubgrid = Xrm.Page.getControl("contact").getGrid();

        var CasesSubgrid = window.parent.document.getElementById("Contacts");

        if (CasesSubgrid == null) {

            setTimeout(function () { FilterCasesSubgrid(); }, 2000); //if the grid hasn’t loaded run this again when it has

            return;

        }

        var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +

        "<entity name='contact'>" +

        "<attribute name='fullname' />" +

        "<filter type='and'>" +

        "<condition attribute='fullname' operator='eq' value='s%' />" +

        "</filter>" +

        "</entity>" +

        "</fetch>";

        if (CasesSubgrid.control != null) {

            //Here i set the fetchxml directly to subgrid

            CasesSubgrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid

            CasesSubgrid.control.Refresh(); //refresh the sub grid using the new fetch xml

        }

        else {

            setTimeout('FilterCasesSubgrid()', 500);

        }

    }

    Please see to that “All Records type” is selected in Records section of Grid, also all the columns mentioned in fetchXml must match with the columns specified in Default View section.

    4137.M12.jpg

    If found useful, please mark this answer as a verified answer.

  • Antonio Lamanna Profile Picture
    165 on at

    Thank you!

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Varsha deshpande Profile Picture

Varsha deshpande 5

#2
JS-09031509-0 Profile Picture

JS-09031509-0 3

#3
Ciprian  P Profile Picture

Ciprian P 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans