Skip to main content

Notifications

Customer Service forum

Set Custom filter for a Sub grid

Posted on by 65

Hi,

I am trying to set custom filter to one of my subgrids. I can see that setParameter("fetchxml", FetchXml) is unsupported. I found gridcontrol.setFilterXml(filter) from methods of subgrid control. But this does not work and also MSDN doesnot provide documentation for this method.

Can anyone suggest me how to use this method or any workaround to filter the subgrid records dynamically.

Categories:
  • RE: Set Custom filter for a Sub grid

    This works for me.

    function SetReleatedEmailSubgrid(executionContext) {

    var isUnified = isUCI();

    if (isUnified) {

    var formContext = executionContext.getFormContext();

    var objSubGrid = formContext.getControl("RelatedEmails");

    var entityId = Xrm.Page.data.entity.getId();

    if (objSubGrid == null) {

    setTimeout(SetReleatedEmailSubgrid(executionContext), 2000);

    return;

    }

    //cc_relatedemailsid is a custom field

    var FetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' returntotalrecordcount='true' page='1' count='4' no-lock='false' >" +

    "<entity name='email' >" +

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

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

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

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

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

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

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

    "<order attribute='createdon' descending='true' />" +

    "<filter type='and' >" +

    "<condition attribute='cc_relatedemailsid' operator='eq' value='" + entityId + "' />" +

    "</filter>" +

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

    "<link-entity name='email' from='activityid' to='cc_relatedemailsid' alias='bb' >" +

    "<filter type='and' >" +

    "<condition attribute='activityid' operator='eq'  value='" + entityId + "' />" +

    "</filter>" +

    " </link-entity>" +

    "</entity>" +

    "</fetch>";

    objSubGrid.setFilterXml(FetchXml);

    objSubGrid.refresh();

    }

    }

    function isUCI() {

    return Xrm.Internal.isUci()

    }

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: Set Custom filter for a Sub grid

    Hi,

    if you want to achieve via supported way,

    1.) web resource (html).

    2.)  you could create multiple pre filter subgrids, and show hide based on conditions. ( Many efforts where there is too many conditions).

    3.)  http://himbap.com/blog/?p=3094

  • Padma Korada Profile Picture
    Padma Korada 65 on at
    RE: Set Custom filter for a Sub grid

    Hi LeoAlt,

    Thanks for your reply.

    Actually am trying to add custom dynamic filter to the sub grid view. Please suggest any supported way to filter it based on a lookup field on the form.

    Above provided links specify unsupported way and MSDN does not provide documentation for filtering sub grid view.

  • Suggested answer
    LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: Set Custom filter for a Sub grid

    Hi Padma,

    If you want to custom filter the subgird, I recommend that you could use OOB function to do this without coding.

    First of all, we should know that the data list we see in the subgirds are all views of entities. So we could custom configure the view filter conditions.

    For example, I want to filter the contact subgrid in account form, so I go to  the account form editor and open the subgrid property, we could see that the defult view is "Active Contacts Subgrid View" , so I go to system customizations and open this view's editor, and then click on "Edit Filter Criteria" then we could add filter conditions to the view follow our requriements.

    community282.png

    community282.png

    community283.png

    By the way, if you want to us js to do this, you could refer to the following posts.

    https://community.dynamics.com/crm/f/117/t/221757

    https://community.dynamics.com/crm/f/117/t/221037

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/controls/addcustomfilter

    Hope it helps.

    Best Regards,

    Leo

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,902 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,302 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans