locked
How to get subgrid Id RRS feed

  • Question

  • In my recent requirement client want to put dynamic view inside subgrid. For this I am using document.getElementById("SubgridName");

    This code is giving me null value. If I use document.getElementById("_SubgridName");, then it give me some values, but most of all the code is not working.

    I referred many blogs like http://blog.navantis.com/dynamically-change-sub-grid-fetchxml-with-a-small-twist-fix/

    Please help me, this is very important.

    Thanks in advance..!!!

    Harsha

    Thursday, March 12, 2015 2:21 PM

Answers

  • Hey Harsha1525,

    Since CRM loads Subgrid controls asynchronously, the most obvious reason to look for would be that you're trying to access a subgrid that's not loaded just yet.

    Additionally, Subgrids support some options such as for example only displaying records that are related to the record you're currently in.

    Anyway, let me know if the below code helped you with loading the subgrid's control!

    var interval = setInterval(function () { GetSubgrid(); }, 1000);
    
    function GetSubgrid() {
    
       var subgrid= Xrm.Page.getControl("YourSubgridName");
    
       if (subgrid!= null) {
    
           clearInterval(timer);            
    
    //add your logic here
    
       }
    }

    • Marked as answer by Harsha1525 Monday, March 16, 2015 12:51 PM
    Saturday, March 14, 2015 11:58 PM
  • Hi,

    document.getElementById("_SubgridName") is coming null because , subgrids loads asynchronously. Thats why you have to check the subgrid element with setInterval function. Check this in my blog. You will understand how subgrid works.

    Filter Subgrid


    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın My blog


    Monday, March 16, 2015 9:36 AM

All replies

  • Hey Harsha1525,

    Since CRM loads Subgrid controls asynchronously, the most obvious reason to look for would be that you're trying to access a subgrid that's not loaded just yet.

    Additionally, Subgrids support some options such as for example only displaying records that are related to the record you're currently in.

    Anyway, let me know if the below code helped you with loading the subgrid's control!

    var interval = setInterval(function () { GetSubgrid(); }, 1000);
    
    function GetSubgrid() {
    
       var subgrid= Xrm.Page.getControl("YourSubgridName");
    
       if (subgrid!= null) {
    
           clearInterval(timer);            
    
    //add your logic here
    
       }
    }

    • Marked as answer by Harsha1525 Monday, March 16, 2015 12:51 PM
    Saturday, March 14, 2015 11:58 PM
  • Hi,

    document.getElementById("_SubgridName") is coming null because , subgrids loads asynchronously. Thats why you have to check the subgrid element with setInterval function. Check this in my blog. You will understand how subgrid works.

    Filter Subgrid


    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın My blog


    Monday, March 16, 2015 9:36 AM
  • Thank you Pedro and Polat for your answers.

    After using setInterval functuion I am getting subgrid Id and controls.

    there is another challeneg I have to change subgrid view with new columns dynamically. I did research on google and found out to do this we can use Layout XML.I  never worked on Layout XML.

    PLease let me know how to change subgrid view dynamically.

    Many thanks in advance.


    Harsha

    Monday, March 16, 2015 12:50 PM