Skip to main content

Notifications

Announcements

No record found.

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

  • Antonio Lamanna Profile Picture
    165 on at
    RE: Filter Subgrid : Cannot read property 'SetParameter' of undefined

    Thank you!

  • Verified answer
    Kalpavruksh D365 CoE Profile Picture
    2,545 on at
    RE: Filter Subgrid : Cannot read property 'SetParameter' of undefined

    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.

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,099 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,884 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans