locked
Unable to get the Subgrid name using javascript in CRM 2011 RRS feed

  • Question

  • Hi All,

    I want refresh the subgrid on my CRM entity page. But i am unable to get the Subgrid name and its properties and methods from javascript.

    I have tried below two options,but these are not working

    1. gridControl = Xrm.Page.ui.controls.get("yourSubGridName");
        gridControl.refresh();

    2. Xrm.Page.ui.controls.get('SuppDocsAttachments').refresh();
     

    Can anyone help me to achive this?

    Any suggestions/ideas would be appriciated.

    Thanks & Regards,
    Priyank Jain

    Wednesday, August 7, 2013 5:30 AM

Answers

  • Priyank,

    Try using this code. I've just tested it and it is working correctly without errors:

    function refreshSubgrid(subgridName) {
        var gridControl = document.getElementById(subgridName);
        if (gridControl != null) {
            Xrm.Page.ui.controls.get(subgridName).refresh();
        }
        else {
            setTimeout(function () {
                refreshSubgrid(subgridName);
            }, 500);
        }
    }

    Paul


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    Thursday, August 8, 2013 10:24 AM

All replies

  • If you're using rollup 12+ then the subgrids are loaded asynchronously - which means OnLoad JavaScript is fired before the subgrids have finished loading.

    My suggestion would be to check if 'gridControl != null' then refresh the grid, otherwise timeout for N milliseconds and then call the same function again. This will ensure it keeps trying until the grid finishes loading.

    If you're worried about infinite loop (for example, if the subgrid just doesn't exist) then you could potentially add a loop counter as a global variable so it doesn't iterate more than a certain number of times.

    Hope that helps

    Paul


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    Wednesday, August 7, 2013 8:53 AM
  • Hi Paul

    I got the subgrid name, but when i am trying to refresh it using the 2nd point mentioned above getting below error,

    ---------------------------
    Message from webpage
    ---------------------------
    There was an error with this field's customized event.

    Field:window

    Event:onload

    Error:'this._control.get_innerControl()' is null or not an object
    ---------------------------
    OK  
    ---------------------------

    Any suggestions/ideas would be appriciated.

    Thanks & Regards,
    Priyank Jain

    Wednesday, August 7, 2013 1:18 PM
  • Can you post the updated code that you are now using? It should look something like this:

    function refreshSubgrid(subgridName) {
        var gridControl = Xrm.Page.ui.controls.get(subgridName);
        if (gridControl != null) {
            gridControl.refresh();
        }
        else {
            setTimeout(function () {
                refreshSubgrid(subgridName);
            }, 500);
        }
    }


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    Wednesday, August 7, 2013 8:21 PM
  • Hi Paul,

    My updated code

    function attachmentGridRefresh() {
        var grid = Xrm.Page.ui.controls.get('SuppDocsAttachments');

        if (grid) {
            if (grid._control._element.readyState == "complete") {

                grid.attachEvent('onrefresh', gridRefresh());
            }
            else {
                setTimeout('attachmentGridRefresh()', 1000);
            }
        }
        else {
            setTimeout('attachmentGridRefresh()', 1000);
        }
    }

    function gridRefresh() {
       
        Xrm.Page.ui.controls.get('SuppDocsAttachments').refresh();
    }

    Thanks & Regards,
    Priyank Jain

    Thursday, August 8, 2013 6:00 AM
  • Hi Paul, I have used your code also. But still i am getting the same above error Error:'this._control.get_innerControl()' is null or not an object Thanks & Regards, Priyank Jain
    Thursday, August 8, 2013 6:05 AM
  • Hello Priyank,

    Did you try to debug your code also which browser you are using ?? because attachEvent will only work in IE, if you are using other browser you need to consider addEventKistener.

    HTH


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, August 8, 2013 6:09 AM
    Moderator
  • Hi Mahender,

    I am using IE 8

    I debugged the code, but get_innerControl() method is throwing error.

    Error:'this._control.get_innerControl()' is null or not an object

    I am searching for solution since last 2 days. But still not got any satisfied solution.

    Request you all to please help me to rectify this problem.

    Thanks & Regards,
    Priyank Jain

    Thursday, August 8, 2013 6:26 AM
  • Did you try to use like this

    var grid = document.getElementById("SuppDocsAttachments");


    Our Website | Our Blog | Follow US | My Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Thursday, August 8, 2013 9:59 AM
    Moderator
  • Priyank,

    Try using this code. I've just tested it and it is working correctly without errors:

    function refreshSubgrid(subgridName) {
        var gridControl = document.getElementById(subgridName);
        if (gridControl != null) {
            Xrm.Page.ui.controls.get(subgridName).refresh();
        }
        else {
            setTimeout(function () {
                refreshSubgrid(subgridName);
            }, 500);
        }
    }

    Paul


    If my response helped you find your answer please show your thanks by taking the time to "Mark As Answer" and "Vote As Helpful".

    Twitter LinkedIn Facebook Blog Magnetism

    Thursday, August 8, 2013 10:24 AM
  • Hi All,

    I got the reason why i was getting above issues.

    After so many research i found that, to refresh a subgrid required some event to occur like onchange of any filed on CRM form. And it is working now.

    Thanks you friends to give me all the above solutions.

    My actual requirement is,
    I want to refresh the subgrid everytime when i add a new attachment to my custom entity.

    How can i achive this, Any solution?

    Thanks & Regards
    Priyank Jain

    Thursday, August 8, 2013 11:31 AM