web
You’re offline. This is a read only version of the page.
close
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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans