From 96023dc221d48417ebd86172fe560ab14f683e3f Mon Sep 17 00:00:00 2001
From: Andre Loreth <a.loreth@adito.de>
Date: Wed, 26 May 2021 12:29:55 +0000
Subject: [PATCH] =?UTF-8?q?[Projekt:=20Entwicklung=20-=20Neon][TicketNr.:?=
 =?UTF-8?q?=201081390][Firmenlookup=20=C3=B6ffnet=20sich=20+=20Fehlermeldu?=
 =?UTF-8?q?ng=20in=20Endlosschleife]=20Check=20existence=20of=20variables?=
 =?UTF-8?q?=20before=20accessing=20them?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

There are certain cases where *.insertedRows/*.changedRows/*.deletedRows variables are NOT available. Therefore an existence check is necessary before accessing them.
One specific case is the following: The "valueProcess" of a parameter in a consumer needs to access any of the above listed variables of another consumer field. This basically works just fine. BUT as soon as you're in a Lookup, the consumer might not be available, therefore the existence check is necessary to prevent an exception.
---
 process/Entity_lib/process.js | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/process/Entity_lib/process.js b/process/Entity_lib/process.js
index afdfbfaa02..79d573a823 100644
--- a/process/Entity_lib/process.js
+++ b/process/Entity_lib/process.js
@@ -504,10 +504,28 @@ EntityConsumerRowsHelper.prototype.fetchRowsFromConsumer = function (pFields)
  */
 EntityConsumerRowsHelper.prototype.applyConsumerRowChanges = function ()
 {
-    var insertedRows = vars.get("$field." + this._consumer + ".insertedRows");
-    var changedRows = vars.get("$field." + this._consumer + ".changedRows");
-    var deletedRows = vars.get("$field." + this._consumer + ".deletedRows");
+    var insertedRows =  null;
+    var changedRows = null;
+    var deletedRows = null;
     
+    // As soon as you're in a Lookup, the consumer might not be available.
+    // Therefore, the existence check for each variable is necessary to prevent an exception.
+    
+    if (vars.exists("$field." + this._consumer + ".insertedRows"))
+    {
+        insertedRows = vars.get("$field." + this._consumer + ".insertedRows")
+    }
+    
+    if (vars.exists("$field." + this._consumer + ".changedRows"))
+    {
+        changedRows = vars.get("$field." + this._consumer + ".changedRows")
+    }
+    
+    if (vars.exists("$field." + this._consumer + ".deletedRows"))
+    {
+        deletedRows = vars.get("$field." + this._consumer + ".deletedRows")
+    }
+        
     if (deletedRows && deletedRows.length > 0)
         this.removeRows(deletedRows);
     if (changedRows && changedRows.length > 0)
-- 
GitLab