Customize OOB Subgrid to show records based on dynamic filter criteria

 OOB dynamic CRM subgrids are limited to static filter criteria's only. If we want to add any dynamic filter criteria to filter records on subgrid then it's not possible with normal subgrid configuration.

However, we can achieve such requirements by customizing fetchxml of view present on subgrid using JavaScript.

eg. If we want to filter accounts on case entity by matching criteria (Current case record Case number = All accounts with matching Account number i.e [case number(case) = account number (account)]) then we can achieve such requirements by using below JavaScript

Add below JS on load of case entity. so that on load it will get case number and filter account subgrid dynamically


function filterAccountSubgridInCase(executionContext) {
    var formContext = executionContext.getFormContext();
    var gridContext = formContext.getControl("Subgrid_Accounts");
    var caseNumber = formContext.getAttribute("new_casenumber").getValue();

    //customizing fetchxml based on dynamic criteria
    var FetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
        "  <entity name='account'>" +
        "    <attribute name='name' />" +
        "    <attribute name='phonenumber' />" +
        "    <attribute name='accountid' />" +
        "    <order attribute='name' descending='false' />" +
        "    <filter type='and'>" +
        "      <condition attribute='statecode' operator='eq' value='0' />" +
        "      <condition attribute='new_accountnumber' operator='eq' value='" + caseNumber + "' />" +
        "    </filter>" +
        "  </entity>" +
        "</fetch>";

    gridContext.setFilterXml(FetchXML);
    formContext.getControl("Subgrid_Accounts").refresh();
}

Comments

Popular posts from this blog

Accessing Fields on QuickView Form through javaScript

ADF - (Part 2) Integrate Data From CRM to External system

Power Apps Portals - Lock/Unlock User Account for Invalid Sign In Attempt