CRM 2011 Multiple Sub-Grid OnLoad Fix

I was recently working with a client where I had to come up with a multi-grid form for Case entity and wanted to display related activities in each grid. And they wanted to display around 6 different types of activities to be available on Case form.

After adding the sub-grids I came to notice a strange issue and as such it does make sense to load records as and when we need them, that is not what my client wanted. Basically what was happening is after I added the sub-grids, only first 4 grids will load the data when form is loaded. Fifth grid onwards I will get a link which will ask me to click on it if I need to see records. This is in fact a good solution to avoid loading unnecessary data and improve performance, client was not happy with that solution. And I was asked to come up with a workaround, it is pretty simple trick as such but can come really handy. You might want to polish it a bit like- make sure that you don’t click on any other link except the one within the grids and maybe some more checks just in case there are other elements with the same class id.

All you need to do is to include this script, on OnLoad of the form along with the jQuery minified library[which you will have to add and make it available on your form.]

function CrmXpress.Scripts.UI.SubGridLoadFix() { 
  
    $(document).ready(function () { 
  
        var links = $("a.ms-crm-List-LoadOnDemand") 
        for (i = 0; i <= links.length; i++) { 
            try { 
                links[i].click(); 
            } 
            catch (e) { 
                // Handle for other errors, or safely ignore 
            } 
        } 
    } 
); 
}

Have fun and Happy Coding.

 

Leave a Reply

Your email address will not be published. Required fields are marked *