web
You’re offline. This is a read only version of the page.
close
Skip to main content
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,626 on at
    RE: Xrm.Page.getControl().getGrid returns null

    Hi,

    when you trigger this function, onload event ? or?

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: Xrm.Page.getControl().getGrid returns null

    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
    RE: Xrm.Page.getControl().getGrid returns null

    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
    RE: Xrm.Page.getControl().getGrid returns null

    I don't have problem with time.

    it can not recognize the control.

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

    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
    RE: Xrm.Page.getControl().getGrid returns null

    hi,

    yes all subgrids,

  • 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

  • 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,

    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

    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

Responsible AI policies

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

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans