Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Xrm.Page.getControl().getGrid returns null

(0) ShareShare
ReportReport
Posted on by

I use this code

function countdistinctitems() {
 var invoiceSubgrid = Xrm.Page.getControl("invoicedetailsgrid");
 var grid = invoiceSubgrid.getGrid();
 var filteredRecordCount = grid.getTotalRecordCount();
 var Rows ;
 var entity ;
 var mainteam ;
 for(i=0;i < filteredRecordCount;i++) {
  Rows(i) = grid.getRows().get(i).getData();
  entity(i) = Rows(i).getEntity();
  mainteam(i) =entity(i).getControl("new_mainteam").getValue();
 }
 mainteam.sort();
 var count = 1;
 for (j=0;j < mainteam.length;j++) {
  if (mainteam[j] != mainteam[j+1]) {
      count +=1
  }   
 }
   Xrm.Page.data.entity.attributes.get("new_field").setValue(count);
}
 

but I get this error:

unable to get property getgrid of undefined or null refrence;

why  subgrid returns null?????

please help me!!!

*This post is locked for comments

  • Suggested answer
    Preeti Sharma Profile Picture
    2,678 on at
    RE: Xrm.Page.getControl().getGrid returns null

    Hi,

    I am not sure if it will work for you but can you please try to replace "Xrm" with "Window.parent.Xrm".

    i.e. try to replace 

     var invoiceSubgrid = Xrm.Page.getControl("invoicedetailsgrid");

    with

     var invoiceSubgrid = window.parent.Xrm.Page.getControl("invoicedetailsgrid");

     

    Hope this helps:)

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Xrm.Page.getControl().getGrid returns null

    Hi

    ; is missing

    Xrm.Page.getControl("invoicedetailsGrid");

  • Community Member Profile Picture
    on at
    RE: Xrm.Page.getControl().getGrid returns null

    I was sure  that I insert the correct name and I test the other subgrids2_2D00_14_2D00_2018-2_2D00_21_2D00_24-PM.png

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: Xrm.Page.getControl().getGrid returns null

    Hi ,

    from the photo you shared the name in your subgrid is different from your code. Case sensitive , please make sure both of them are same.

  • Suggested answer
    sardar ahmed Profile Picture
    520 on at
    RE: Xrm.Page.getControl().getGrid returns null

    Hi

    "G" is capital in your name, "invoicedetailsGrid".

    Please change it in the below line.

    var invoiceSubgrid = Xrm.Page.getControl("invoicedetailsgrid");

    Hope this helps.

    Mark it as answered if it resolves your issue.

  • Community Member Profile Picture
    on at
    RE: Xrm.Page.getControl().getGrid returns null

    how I can get sbgrisd value with fetchxml?i think it works better

  • Community Member Profile Picture
    on at
    RE: Xrm.Page.getControl().getGrid returns null

    2_2D00_14_2D00_2018-2_2D00_03_2D00_01-PM.png 

    I sure

  • sardar ahmed Profile Picture
    520 on at
    RE: Xrm.Page.getControl().getGrid returns null

    Hi,

    Section or Tab should not be a problem.

    please make sure that you are using the name as shown below

    3122.Grid.PNG

  • Community Member Profile Picture
    on at
    RE: Xrm.Page.getControl().getGrid returns null

    I think because the subgrid is in the section within the  tab

    what do you think?

  • sardar ahmed Profile Picture
    520 on at
    RE: Xrm.Page.getControl().getGrid returns null

    Hi Esmaeel8574,

    I have used your code to get the grid on the form.

    I was able to successfully get the sub-grid. with the below line.

    var invoiceSubgrid = Xrm.Page.getControl("invoicedetailsgrid");

    Can you cross verify the name of the subgrid, I think there is a typo in the name or your giving display name instead of name.

    Thanks and Regards

    Sardar Ahmed

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans