Refresh Subgrid to include workflow created records (code posted with error) RRS feed

  • Question

  • first of all here is the reference that I used to base the code off of: http://microxrm.blogspot.com/2013/07/retrieving-subgrid-items-count-using.html

    I am posting code.   I am having trouble getting the number of records in the grid and then suppressing the refresh if a certain number of records are there.  I'm using an interval.              

    See the comments "//" the 2nd and 3rd lines.  I'm pretty sure that is where it fails.

    I'm open to doing this in a different way.  The key is that we are creating associated records 'onload' through workflow and need the  grid to reload once the records are there.

    function refresh_init() {    
                    setInterval(function () { refact() }, 1000);
                    setInterval(function () { refcnt() }, 1000);

                function refact()
                    var LinkedAccounts = Xrm.Page.ui.controls.get("LinkedAccounts");
                    if (LinkedAccounts != null) {
                        var countAct = LinkedAccounts.get_innerControl().get_allRecordIds().length; // causes error
                    if (countAct < 16) {


                function refcnt()
                    var LinkedContacts = Xrm.Page.ui.controls.get("LinkedContacts");
                    if (LinkedContacts != null) {
                        var countCnt = LinkedContacts.get_innerControl().get_allRecordIds().length;   // causes error
                    if (countCnt < 16) {

    Tuesday, July 7, 2015 4:01 PM

All replies

  • As there seems to be no supported way of retrieving the record counts via client script, you could use REST endpoint to retrieve the record count. Also, it is best to use setTimeout rather than setInterval, so you have control when to stop the refresh. Otherwise, you would be hitting the server infinitely until the window is closed.
    Wednesday, July 8, 2015 12:38 AM