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

Announcements

News and Announcements icon
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

I have the same question (0)
  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    when you trigger this function, onload event ? or?

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi Esmaeel ,

    If you are calling your method in on-load then you can try to call inside setinterval - 

    var intervalId = window.setInterval(

           function () {

               countdistinctitems() ;

           }

           , 2000);

  • Community Member Profile Picture
    on at

    onload,onsave   both of them

    I use settimeout but it falls in loop because it returns null every time.

    it can not returns the subgrid control

  • Community Member Profile Picture
    on at

    I don't have problem with time.

    it can not recognize the control.

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    is this happen to other subgrid as well?

    If No, lets try to remove the subgrid, save and publish, Add again.

  • Community Member Profile Picture
    on at

    hi,

    yes all subgrids,

  • sardar ahmed Profile Picture
    520 on at

    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

  • Community Member Profile Picture
    on at

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

    what do you think?

  • sardar ahmed Profile Picture
    520 on at

    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

    2_2D00_14_2D00_2018-2_2D00_03_2D00_01-PM.png 

    I sure

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans