web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get Subgrid Id

(0) ShareShare
ReportReport
Posted on by 35

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

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahadeo Matre Profile Picture
    17,021 on at

    Hi Harsha,

    You have to use bellow name when trying to get sub grid

    You will get null when you are calling this function on form load.. because sub grids are not loading same time as form is loaded.. it will take some time..

     That's why you need to use timeout function 

    if (objSubGrid == null || objSubGrid.readyState != "complete") {
    setTimeout(dynamicallyFilterSubGrid, 2000);
    return;
    }

    This function will be called multiple times until subgrid is not loaded on form.. once subgrid is loaded then you can filter your grid using fetchxml.. 

    One thing i want mention is that.. this is unsupported customization.. 

  • rikrokNA Profile Picture
    145 on at

    I'm on the online version of CRM, how in the world do I get to that screen?

  • Suggested answer
    necsa Profile Picture
    3,455 on at

    Hi rikrokNA,

    Go to Settings ->Customization -> Customizations  then select "Customize the system"

    then

    expand there "Entities" select the entity where subgrid located then open main Form, in the main Form select which subgrid do you want to see, Double click on the subgrid you will get that screen.

    -You must have customization or Admin securityrole if you have follow;

    set8.jpg

    set2.jpg

    set3.jpg

    set4.jpg

    set5.jpg

    set6.jpg

    set7.jpg

    set8.jpg

    thanks

    Happy CRM

  • rikrokNA Profile Picture
    145 on at

    Thank you very much for that....helped me a ton.

  • Suggested answer
    Hemant Kumar Sahu Profile Picture
    1,829 on at

    Hi ,

    Sub grid takes time to load.Try time out.

      function subGridA_OnLoad () {

           // retrieve the subgrid

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

           // if the subgrid still not available we try again after 2 second

           if (grid == null) {

               setTimeout(subGridA_OnLoad, 200);

               return;

           }

               }

    Thanks

    Hemant

  • necsa Profile Picture
    3,455 on at

    Hi Hemant Sahu,

    you give too short time. for 2 second take 2000 and try it again

    a another tip:

    function subGridA_OnLoad (){
     
        //get the subgrid
        var objSubGrid = window.parent.document.getElementById("accountcontractsgrid");
     
        //CRM loads subgrid after form is loaded.. so when we are adding script on form load.. need to wait until sub grid is loaded.
        // that's why we are adding a delay..
        var isGridLoaded = null;
        try {isGridLoaded = objSubGrid.control.getEntityName();}
        catch(err)
        {  
            setTimeout(filterContractsGrid, 2000);
        return;
        }

    or try this code;

    function subGridOnload()
    {
     //debugger;
     var grid = Xrm.Page.ui.controls.get('Opps')._control;

     if  (grid.get_innerControl()==null)
     {
      setTimeout(subGridOnload, 1000);
      return;
     }
     else if (grid.get_innerControl()._element.innerText.search("Loading")!= -1)
     {
      setTimeout(subGridOnload, 1000);
      return;
     }
    }

    just as tip: document.getElemenById("subgrid")  is unsupported code for CRM 2015

  • rikrokNA Profile Picture
    145 on at

    Necdet Saritas , you seem to know your stuff. I appreciate this wealth of information you're posting.

    That tip about  document.getElemenById("subgrid") has been very enlightening, I have been struggling to find out what in the world the Xrm.Page is named. If you have a second or have the want, please check out community.dynamics.com/.../489780.

  • Albert_ Profile Picture
    458 on at

    In my oponion, you got the best answer award of all time !
    Thanks !
    You helped me !

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans