Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Xrm.Page.getControl().getGrid returns null

Posted on by Microsoft Employee

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
    Preeti Sharma 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
    Alex Fun Wei Jie 33,626 on at
    RE: Xrm.Page.getControl().getGrid returns null

    Hi

    ; is missing

    Xrm.Page.getControl("invoicedetailsGrid");

  • Community Member Profile Picture
    Community Member Microsoft Employee 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
    Alex Fun Wei Jie 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
    sardar ahmed 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
    Community Member Microsoft Employee 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
    Community Member Microsoft Employee 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
    sardar ahmed 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
    Community Member Microsoft Employee 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
    sardar ahmed 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans