Monday, June 24, 2013

CRM 2011 Filtered sub grid

Filtered sub grid is very commonly used feature in CRM 2011.
As you may already know we can use CRM default feature to filter sub grid data by selecting different views for sub grid. But you may come across situations where system needs to filter sub grid data based on opening record field,
For example you need to filter Contact sub grid based on Account form City field. So sub grid should only Contacts which have same city as Account City:
In this kind of scenario we can use javascript to add filter to the sub grid.

Use advance find and generate fetch xml for filter contact

function setContactSubGrid() {
    var grid = $('#accountContactsGrid')[0];
    var accountCity = Xrm.Page.getAttribute("address1_city").getValue();
    if (grid == null || grid.readyState != "complete") {
        setTimeout('setContactSubGrid()', 2000);
    }
    else {

        var fetchXml = "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "";
            
        grid.control.setParameter("fetchXml", fetchXml);

        grid.control.refresh();
    }
}
Call this function on Account onLoad event.

No comments:

Post a Comment

MS CRM 2011 KB Article customization Issue.

Recently I have encountered some issue while customizing Kb Article Entity. I was doing following configuration in Article form. 1. Add Ba...