locked
CRM online 2016 getTotalRecordCount RRS feed

  • Question

  • Hi,

    I would like to display the total number of rows in Contacts subgrid on Account form. My code is:

    function recordcount()
    {
        var TRC = Xrm.Page.getControl("accountcontactsgrid").getGrid().getTotalRecordCount();
        Xrm.Page.getAttribute("eg_recordcount").setValue(TRC)
    }

    But I am getting error:

    TypeError: Unable to get property 'getGrid' of undefined or null reference at recordcount

    Can somebody help.

    Br

    Monday, August 22, 2016 4:52 PM

All replies

  • Hi Pulkit,

    It is already answered here by Sam

    "You can get number of rows in supported way using Xrm.Page.getControl("name").getGrid().getTotalRecordCount() by adding timeout before for the javascript code because subgrid takes some time to load after the form is loaded.

    If subgrid is not completly loaded with all records then it returns wrong number of records.

    Refer below blog for identifying event for records added or removed on sub grid."

    Identify the trigger for an On-load event for Sub-grid in Dynamics CRM

    Modify Your function as stated above as below

    function recordcount() {
    
    
        try {
    
            //setting timeout beacuse subgid take some time to load after the form is loaded
    
            setTimeout(function () {
    
                //validating to check if the sub grid is present on the form
    
                if (Xrm.Page != null && Xrm.Page != undefined && Xrm.Page.getControl("accountcontactsgrid") != null && Xrm.Page.getControl("accountcontactsgrid") != undefined) {
    
                    //stores the row count of subgrid on load event of CRM Form
    
                var  _rowCount = Xrm.Page.getControl("accountcontactsgrid").getGrid().getTotalRecordCount();
    
                     alert(  _rowCount);
    
    
    
                }
    
            }, 5000);
    
        } catch (e) {
    
            Xrm.Utility.alertDialog(functionName + "Error: " + (e.message || e.description));
    
        }
    
    }

    Hope it helps.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in

    Monday, August 22, 2016 6:57 PM