JavaScript Проблема с веб-ресурсом: внезапно начал работать getGrid () - PullRequest
0 голосов
/ 09 апреля 2020

У меня есть несколько различных JavaScript веб-ресурсов, которые используют getGrid (), все из которых начали давать сбои на этой неделе после того, как я включил Обновления 2020 Wave 1 в D365. Сообщение об ошибке показывает:

"Произошла ошибка: Ошибка типа: невозможно получить свойство 'getGrid' с неопределенной или нулевой ссылкой"

Вот мой код:

function GetTotalResourceCount(executionContext) {
   console.log("function started");
   var execContext = executionContext;
   var formContext = executionContext.getFormContext();
   var resourceyescount = 0;
   try {
      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)
   }
}

Вот отдельный веб-ресурс, который вызывает функцию:

function TriggerSalesQDResourceCount(executionContext){
var formContext = executionContext.getFormContext();
formContext.getControl("s_qd").addOnLoad(GetTotalResourceCount);
}

Есть идеи, как я могу это исправить? Это известная проблема с новым обновлением D365 wave 1? Спасибо!

1 Ответ

3 голосов
/ 10 апреля 2020

Эта проблема связана с использованием неподдерживаемого (недокументированного) кода, которое будет прервано в будущих обновлениях.

Неподдерживаемое :

var gridCtx = formContext._gridControl;

Вам необходимо переключиться на эти поддерживаемые методы.

function doSomething(executionContext) {
   var formContext = executionContext.getFormContext(); // get the form Context
   var gridContext = formContext.getControl("Contacts"); // get the grid context

   // Perform operations on the subgrid

   var grid = gridContext.getGrid();

}

Ссылки :

Контекст сетки API клиента

Grid (Client API ссылка)

...