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 :
Customer experience | Sales, Customer Insights,...
Suggested answer

JavaScript Web Resource issue: getGrid() suddenly started failing

(0) ShareShare
ReportReport
Posted on by

Hello, I have a few different JavaScript web resources that use the getGrid(), all of which started failing this week after I enabled the 2020 Wave 1 Updates in D365.  The error message shows: "Error occurred :TypeError: Unable to get property 'getGrid' of undefined or null reference"

An example of a line of code that is suddenly failing in each of my web resources is:

        var grid = gridCtx.getGrid();

gridCtx is a variable that I previously defined in my code.

Any ideas how I can fix this? Is this a known issue with the new D365 wave 1 update?

Thanks!

I have the same question (0)
  • Suggested answer
    Marco.P Profile Picture
    2,405 on at
    RE: JavaScript Web Resource issue: getGrid() suddenly started failing

    Hi,

    How do you define gridCtx?

    Anyway, here's a link that helped me manage my transition and revision of my js code:

    www.google.com/.../

    An extract:

    Earlier

    Xrm.Page.getControl(“Contacts”).getGrid();

    Now

             gridContext.getGrid();

    //where griContext = formContext.getControl(“Contacts”);

    Hope it helps,

    Marco

  • Suggested answer
    Malini Johari Profile Picture
    160 on at
    RE: JavaScript Web Resource issue: getGrid() suddenly started failing

    Hi,

    Please try gridContext=formContext.getControl("controlName");

    and then gridContext.getGrid();

  • Community Member Profile Picture
    on at
    RE: JavaScript Web Resource issue: getGrid() suddenly started failing

    @Malani,

    That removed the error, but now the code still does not run execute.  It was working prior to the Wave 1 update.  Here is my web resource code:

    function GetTotalResourceCount(executionContext) {

       console.log("function started");

       var execContext = executionContext;

       var formContext = executionContext.getFormContext();

       var resourceyescount = 0;

       try {

    var gridContext=formContext.getControl("s_qd");

    var grid = gridContext.getGrid();

          // var gridCtx = formContext._gridControl;

           //var grid = gridCtx.getGrid();

           var allRows = grid.getRows();

           var duplicatesFound = 0;

           //loop through rows and get the attribute collection

           allRows.forEach(function (row, rowIndex) {

               var thisRow = row.getData().entity;

               var thisRowId = thisRow.getId();

    var thisResource = "";

    var thisResourceName = "";

    var thisResourceID = "";

               console.log("this row id=" + thisRowId);

               var thisAttributeColl = row.getData().entity.attributes;

               thisAttributeColl.forEach(function (thisAttribute, attrIndex) {

                   var msg = "";

                   if (thisAttribute.getName() == "new_resource") {

                       thisResource = thisAttribute.getValue();

    thisResourceID = thisResource[0].id;

    thisResourceName = thisResource[0].name;

    console.log("this resource name=" + thisResourceName)

                   }

               });

               var allRows2 = formContext.getGrid().getRows();

               //loop through rows and get the attribute collection

               allRows2.forEach(function (row, rowIndex) {

                   var thatRow = row.getData().entity;

                   var thatRowId = thatRow.getId();

                   var thatAttributeColl = row.getData().entity.attributes;

    var thatResource = "";

    var thatResourceName = "";

    var thatResourceID = "";

                   thatAttributeColl.forEach(function (thatAttribute, attrIndex) {

                       if (thatAttribute.getName() == "new_resource") {

                           thatResource = thatAttribute.getValue();

    thatResourceID = thatResource[0].id;

    thatResourceName = thatResource[0].name;

                           if (thatResourceID == thisResourceID && thatRowId != thisRowId) {

                               duplicatesFound++;

                               var msg = "Duplicate resource " + thatResource;

    console.log("duplicates found= " + duplicatesFound);

                           }

                       }

                   });

               });

           });

           if (duplicatesFound > 0) {

               console.log("duplicate found");

    Xrm.Page.getAttribute("new_showduplicateerror").setValue(true);

    Xrm.Page.getControl("new_showduplicateerror").setVisible(true);

    Xrm.Page.getControl("new_showduplicateerror").setNotification("A duplicate resource was found.  Please remove this before saving.");

           } else {

    Xrm.Page.getAttribute("new_showduplicateerror").setValue(false);

    Xrm.Page.getControl("new_showduplicateerror").setVisible(false);

    Xrm.Page.getControl("new_showduplicateerror").clearNotification();

    }

       } catch (err) {

           console.log('Error occurred :' + err)

       }

    }

    Here is a separate web resource that triggers the function:

    function TriggerSalesQDResourceCount(executionContext){

    var formContext = executionContext.getFormContext();

    formContext.getControl("s_qd").addOnLoad(GetTotalResourceCount);

    }

    Any ideas how I can fix this?

    Thanks!

  • Marco.P Profile Picture
    2,405 on at
    RE: JavaScript Web Resource issue: getGrid() suddenly started failing

    Replace Xrm.Page with executionContext.getFormContext();.

    You're still using deprecated API

  • Community Member Profile Picture
    on at
    RE: JavaScript Web Resource issue: getGrid() suddenly started failing

    @Marco.P,

    Thank you.  Are you referring to these 6 lines?:

    Xrm.Page.getAttribute("new_showduplicateerror").setValue(true);

    Xrm.Page.getControl("new_showduplicateerror").setVisible(true);

    Xrm.Page.getControl("new_showduplicateerror").setNotification("A duplicate resource was found.  Please remove this before saving.");

          } else {

    Xrm.Page.getAttribute("new_showduplicateerror").setValue(false);

    Xrm.Page.getControl("new_showduplicateerror").setVisible(false);

    Xrm.Page.getControl("new_showduplicateerror").clearNotification();

    }

    Should I just replace them to look something like the example below?:

    executionContext.getFormContext().getAttribute("new_showduplicateerror").setValue(true);

    If yes, that portion of the code is still working, so I am not sure that is the issue.

  • Sarah Daniel Beshay Profile Picture
    on at
    RE: JavaScript Web Resource issue: getGrid() suddenly started failing

    Hi tgiard,

    As Marco.P advised Xrm.Page is deprecated and you should be using formContext instead, please check the article below and make sure to update your code:

    docs.microsoft.com/.../important-changes-coming

    Here's an example of getAttribute function:

    docs.microsoft.com/.../getattribute

    Can you please clarify further on the current state of the code? When you say the code doesn't execute, which part of the code isn't working?

    You can add more logs to your code to know which part of the code is failing. Once you do that kindly share with us where the issue is happening to be able to assist you further.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 235

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 177

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 156 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans