Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

SubGrid lookup filter wont work

Posted on by Microsoft Employee

Hello,

I have a Problem with the subgrid element in CRM 2016.

I want to select users in a subgrid from a prefiltert lookup. But it doesnt work. i dont get an error or something like this. The looup field just doesnt filter the users in the lookup field. i use the following Java script code. Does anyone have an idear whats wrong with my code?

 function filterSubGrid() {

        var grid = window.parent.document.getElementById("GridName");
        var currentleadId = Xrm.Page.data.entity.getId();;
        if (grid == null) {
            setTimeout(filterSubGrid, 500);
            return;
        }


        var fetch = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"
        + "<entity name='systemuser'>"
        + "<attribute name='fullname' />"
        + "<attribute name='title' />"
        + "<attribute name='address1_telephone1' />"
        + "<attribute name='businessunitid' />"
        + "<attribute name='siteid' />"
        + "<attribute name='positionid' />"
        + "<attribute name='systemuserid' />"
        + "<order attribute='fullname' descending='false' />"
        + "<filter type='and" >
        +"<condition attribute='isdisabled' operator='eq' value='0' />"
        + "<condition attribute='accessmode' operator='ne' value='3' />"
        + "<condition attribute='accessmode' operator='ne' value='5' />"
        + "<condition attribute='oldUser' operator='eq' value='1' />"
        + "</filter>"
        + "</entity>"
        + "</fetch>";

        if (grid.control != null) {
            debugger;
            grid.control.SetParameter("fetchXML", fetch);
            grid.control.refresh();
        }
        else {
            setTimeout('filterSubGrid()', 500);
        }
    }

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SubGrid lookup filter wont work

    Hello thanks for the quick answers.

    I changed my code to :

    function filterSubGrid() {

           var grid = document.getElementById("grdName");

           if (grid == null) {

               setTimeout(filterSubGrid, 500);

               return;

           }

           var fetchXml = "<count='50' >"

           + "<entity name='systemuser'>"

           + "<attribute ='fullname' />"

           + "<filter type='and' >"

           + "<condition attribute='isUsefull' operator='eq' value='1' />"

           + "</filter>"

           + "</entity>"

           + "</fetch>";

           // change view of subgrid

           grid.control.SetParameter("fetchXml", fetchXml);

           grid.control.refresh();

       }

    I still dont get an error.

    grid contains an object and is not null

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SubGrid lookup filter wont work

    1. Try using "document.getElementById("YourGridName")" instead of   "window.parent.document.getElementById("GridName")"

    2. If you are fetching leadId then why are you not using it in your fetch xml.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SubGrid lookup filter wont work

    Are You want to Filter Grid based on lookup value? 

    1. It seems you are not passing the lookup Guid(Id) to fetchxml.

    2. You getting leadid but not using it any where.

    may be due to that points your filter grid not working.

  • Suggested answer
    Yadnyesh Kuvalekar Profile Picture
    Yadnyesh Kuvalekar 4,102 on at
    RE: SubGrid lookup filter wont work

    As you are not getting error, it seems that your grid variable is having null value. Try debugging your code and check if below statement is giving the grid object.

    window.parent.document.getElementById("GridName");

    Microsoft has removed support on accessing DOM elements and hence it is not recommended. This seems to be an issue.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans