Bladeren bron

Merge branch 'CopyCard_FixError' of github.com:Firas-Git/wekan into Firas-Git-CopyCard_FixError

Lauri Ojansivu 2 maanden geleden
bovenliggende
commit
38e57d3635
1 gewijzigde bestanden met toevoegingen van 23 en 13 verwijderingen
  1. 23 13
      models/cards.js

+ 23 - 13
models/cards.js

@@ -531,20 +531,30 @@ Cards.helpers({
   mapCustomFieldsToBoard(boardId) {
     // Map custom fields to new board
     return this.customFields.map(cf => {
-      const oldCf = ReactiveCache.getCustomField(cf._id);
-      const newCf = ReactiveCache.getCustomField({
-        boardIds: boardId,
-        name: oldCf.name,
-        type: oldCf.type,
-      });
-      if (newCf) {
-        cf._id = newCf._id;
-      } else if (!_.contains(oldCf.boardIds, boardId)) {
-        oldCf.addBoard(boardId);
-      }
-      return cf;
+        const oldCf = ReactiveCache.getCustomField(cf._id);
+
+        // Check if oldCf is undefined or null
+        if (!oldCf) {
+            console.error(`Custom field with ID ${cf._id} not found.`);
+            return cf;  // Skip this field if oldCf is not found
+        }
+
+        const newCf = ReactiveCache.getCustomField({
+            boardIds: boardId,
+            name: oldCf.name,
+            type: oldCf.type,
+        });
+
+        if (newCf) {
+            cf._id = newCf._id;
+        } else if (!_.contains(oldCf.boardIds, boardId)) {
+            oldCf.addBoard(boardId);
+        }
+
+        return cf;
     });
-  },
+},
+
 
   copy(boardId, swimlaneId, listId) {
     const oldId = this._id;