Skip to content

Javascript error - Cannot read properties of null (reading 'toISOString') #713

@niicoooo

Description

@niicoooo

Hi,

I have a javascript issue with the "Inventoy detail" screen, http://127.0.0.1:8000/data/input/operationplanmaterial/. An javascript error is displayed in the browser console when a record is selected and we try to update a Manufacturing Order with the "Manufacturing Order" widget

frePPLe version: commit aa316b3
DB version: PostgreSQL 13.4

Error:

angular.min.js:117 TypeError: Cannot read properties of null (reading 'toISOString')
    at operationplandetailCtrl.js:72:103
    at c (angular.min.js:139:384)
    at m.$eval (angular.min.js:145:107)
    at m.$digest (angular.min.js:142:173)
    at b.$apply (angular.min.js:145:401)
    at HTMLButtonElement.<anonymous> (angular.min.js:274:446)
    at HTMLButtonElement.dispatch (jquery-3.6.0.min.js:2:43064)
    at HTMLButtonElement.<anonymous> (jquery-3.6.0.min.js:2:41048)

Solution:

--- a/freppledb/input/static/operationplandetail/src/operationplandetailCtrl.js
+++ b/freppledb/input/static/operationplandetail/src/operationplandetailCtrl.js
@@ -69,13 +69,13 @@ function operationplanCtrl($scope, $http, OperationPlan, PreferenceSvc) {
         }
         if (oldValue[0] === newValue[0] && newValue[0] !== -1) {
           //is a change to the current operationplan
-          if (typeof oldValue[1] !== 'undefined' && typeof newValue[1] !== 'undefined' && oldValue[1].toISOString() !== newValue[1].toISOString()) {
+          if (typeof oldValue[1] !== 'undefined' && typeof newValue[1] !== 'undefined' && oldValue[1] !== null && newValue[1] !== null && oldValue[1].toISOString() !== newValue[1].toISOString()) {
             if ($scope.mode == "kanban" || $scope.mode.startsWith("calendar"))
               $scope.$broadcast("selectedEdited", "startdate", oldValue[1], new Date($scope.operationplan.start));
             else
               $scope.displayongrid($scope.operationplan.id, "startdate", $scope.operationplan.start);
           }
-          if (typeof oldValue[2] !== 'undefined' && typeof newValue[2] !== 'undefined' && oldValue[2].toISOString() !== newValue[2].toISOString()) {
+          if (typeof oldValue[2] !== 'undefined' && typeof newValue[2] !== 'undefined' && oldValue[2] !== null && newValue[2] !== null && oldValue[2].toISOString() !== newValue[2].toISOString()) {
             if ($scope.mode == "kanban" || $scope.mode.startsWith("calendar"))
               $scope.$broadcast("selectedEdited", "enddate", oldValue[2], new Date($scope.operationplan.end));
             else

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions