Aug 6, 2013

Microsoft CRM 2011, automatically load all subgrids

Microsoft CRM 2011 doesn't load by default data in all of the subgrids if they count exceed 4, displaying 'To load ... records, click here' message. It's actually extremely annoying.

It's not possible to change this behaviour with standard tools (i.e. via control preferences). So I've found how to do it using JavaScript function call on form OnLoad event. Unfortunatelly it did't worked in my case. For some reason the moment then OnLoad event was fired, the from subgrids were, apparently, not initialized on the form. I've decided then to call the function with a little delay:

var autoLoadSubgrids = function() {
    var maxAuto = 4;
    var loadDelay = 1000;

    var subgrids = Xrm.Page.ui.controls.get(function (control, index) {
        return control.getControlType() == "subgrid";
    });
    
    if (subgrids.length > maxAuto) {
        var subCall = function() {
            var i;
            for (i = maxAuto; i < subgrids.length; i++) {
                var grid = subgrids[i];
                if(grid != null) {
                    grid.refresh();
                }
            }
        };

        window.setTimeout(subCall, loadDelay);
    }
};

And it worked! Not the solution I would like, but I guess that's all I can do now and it also would'n do any harm if something goes wrong.

2 comments:

  1. Thanks Petr, this solution indeed works !

    ReplyDelete
  2. best crm for small business Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info.

    ReplyDelete