From 5943a263e526e7742b6b9de9db88c18950847a26 Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Thu, 25 Jul 2019 12:10:09 +0200
Subject: [PATCH] correct usage of rowdata in on db update in some record
 containers

---
 .../recordcontainers/db/onDBUpdate.js         |  8 ++-
 .../recordcontainers/db/onDBUpdate.js         |  6 +-
 .../recordcontainers/db/onDBUpdate.js         | 10 ++--
 .../recordcontainers/db/onDBUpdate.js         | 55 ++++++++++---------
 .../entityfields/quantity/valueProcess.js     | 18 +++---
 .../recordcontainers/db/onDBUpdate.js         |  2 +-
 .../recordcontainers/db/onDBUpdate.js         |  4 +-
 .../recordcontainers/db/onDBUpdate.js         | 20 +++----
 process/KeywordRegistry_basic/process.js      |  1 +
 9 files changed, 64 insertions(+), 60 deletions(-)

diff --git a/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js b/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js
index 345ac72193..9614bc5ae5 100644
--- a/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js
@@ -10,6 +10,8 @@ import("Bulkmail_lib");
 
 //TODO - Function
 
+var rowdata = vars.get("$local.rowdata");
+
 var content = vars.get("$field.content");
 var originalBinData = vars.get("$field.BINDATA");
 var filename, type, template;
@@ -22,7 +24,7 @@ if(vars.get("$field.BINDATA"))
 }
 else
 {
-    template = BulkMailUtils.getBulkMailTemplate(vars.get("$field.BULKMAILID"), vars.get("$field.DOCUMENTTEMPLATE_ID"));
+    template = BulkMailUtils.getBulkMailTemplate(vars.get("$local.uid"), rowdata["BULKMAIL.DOCUMENTTEMPLATE_ID"]);
     type = template.type;
 }
 
@@ -31,13 +33,13 @@ if (type == DocumentTemplate.types.EML || type == DocumentTemplate.types.HTML)
 
 var bindata = util.encodeBase64String(content);
 if (!filename)
-    filename = vars.get("$field.NAME") + ".txt";
+    filename = rowdata["BULKMAIL.NAME"] + ".txt";
 
 if(bindata != "")
 {
     let sysAlias = "_____SYSTEMALIAS";
     var binaryId = db.cell(SqlCondition.begin(sysAlias)
-        .andPrepareVars("ASYS_BINARIES.ROW_ID", "$field.BULKMAILID")
+        .andPrepareVars("ASYS_BINARIES.ROW_ID", "$local.uid")
         .buildSql("select ID from ASYS_BINARIES", "1=2"), sysAlias);
     db.updateBinary(binaryId, "", bindata, filename, "", "", sysAlias);
     neon.refresh(["$field.content"]);
diff --git a/entity/Communication_entity/recordcontainers/db/onDBUpdate.js b/entity/Communication_entity/recordcontainers/db/onDBUpdate.js
index 7c2c746ae9..3a419c8be4 100644
--- a/entity/Communication_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Communication_entity/recordcontainers/db/onDBUpdate.js
@@ -4,7 +4,7 @@ import("StandardObject_lib");
 
 var rowdata = vars.get("$local.rowdata");
 
-new StandardObject("Communication", vars.get("$field.COMMUNICATIONID"), "Person", vars.get("$field.CONTACT_ID"))
-    .onCommunicationUpdate(vars.get("$field.MEDIUM_ID"));
+new StandardObject("Communication", vars.get("$local.uid"), "Person", rowdata["COMMUNICATION.CONTACT_ID"])
+    .onCommunicationUpdate(rowdata["COMMUNICATION.MEDIUM_ID"]);
     
-DataPrivacyUtils.notifyNeedDataPrivacyUpdate(vars.get("$field.CONTACT_ID"), vars.get("$param.ShowDsgvoMessage_param"));
\ No newline at end of file
+DataPrivacyUtils.notifyNeedDataPrivacyUpdate(rowdata["COMMUNICATION.CONTACT_ID"], vars.get("$param.ShowDsgvoMessage_param"));
\ No newline at end of file
diff --git a/entity/DSGVOInfo_entity/recordcontainers/db/onDBUpdate.js b/entity/DSGVOInfo_entity/recordcontainers/db/onDBUpdate.js
index e8669f4fa4..ef08b6011a 100644
--- a/entity/DSGVOInfo_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/DSGVOInfo_entity/recordcontainers/db/onDBUpdate.js
@@ -1,12 +1,14 @@
 import("system.vars");
 import("DataPrivacy_lib");
 
+var rowdata = vars.get("$local.rowdata");
+
 if (vars.get("$param.ReportType_param"))
     DataPrivacyUtils.openReport(vars.get("$param.ContactId_param"), vars.get("$param.ReportType_param"), {
-        datasource: vars.get("$field.DATASOURCE"),
-        transmission: vars.get("$field.TRANSMISSION"),
-        recipient: vars.get("$field.RECIPIENT"),
-        garantees: vars.get("$field.GUARANTEE"),
+        datasource: rowdata["DSGVOINFO.DATASOURCE"],
+        transmission: rowdata["DSGVOINFO.TRANSMISSION"],
+        recipient: rowdata["DSGVOINFO.RECIPIENT"],
+        garantees: rowdata["DSGVOINFO.GUARANTEE"],
         requestDate: vars.get("$field.dateRequest"),
         deadline: vars.get("$field.deadline"),
         deadlineDate: vars.get("$field.dateDeadline")
diff --git a/entity/DocumentTemplate_entity/recordcontainers/db/onDBUpdate.js b/entity/DocumentTemplate_entity/recordcontainers/db/onDBUpdate.js
index df234535f2..0fb8777c9a 100644
--- a/entity/DocumentTemplate_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/DocumentTemplate_entity/recordcontainers/db/onDBUpdate.js
@@ -1,27 +1,30 @@
-import("system.util");
-import("system.vars");
-import("system.db");
-import("Document_lib");
-
-//TODO - Function
-
-var bindataUpload = DocumentUtil.getBindataFromUpload(vars.get("$field.BINDATA"));
-var filename      = "";
-var bindata       = "";
-
-if(bindataUpload != "")
-{
-    bindata = bindataUpload;
-    filename = DocumentUtil.getFilenameFromUpload(vars.get("$field.BINDATA"));
-}
-else if(vars.get("$field.TYPE").trim() == "TEX" && vars.get("$field.texText") != "")
-{
-    filename = vars.get("$field.NAME") + ".txt";
-    bindata  = util.encodeBase64String(vars.get("$field.texText"));
-}
-
-if(bindata != "" && filename != "")
-{
-    var binaryId      = db.cell("select ID from ASYS_BINARIES where ROW_ID = '" + vars.get("$field.DOCUMENTTEMPLATEID") + "'", "_____SYSTEMALIAS");
-    db.updateBinary(binaryId, "", bindata, filename, "", "", "_____SYSTEMALIAS");
+import("system.util");
+import("system.vars");
+import("system.db");
+import("Document_lib");
+import("Sql_lib");
+
+//TODO - Function
+
+var rowdata = vars.get("$local.rowdata");
+
+var bindataUpload = DocumentUtil.getBindataFromUpload(vars.get("$field.BINDATA"));
+var filename      = "";
+var bindata       = "";
+
+if(bindataUpload != "")
+{
+    bindata = bindataUpload;
+    filename = DocumentUtil.getFilenameFromUpload(vars.get("$field.BINDATA"));
+}
+else if(rowdata["DOCUMENTTEMPLATE.TYPE"].trim() == "TEX" && vars.get("$field.texText") != "")
+{
+    filename = rowdata["DOCUMENTTEMPLATE.NAME"] + ".txt";
+    bindata  = util.encodeBase64String(vars.get("$field.texText"));
+}
+
+if(bindata != "" && filename != "")
+{
+    var binaryId      = db.cell("select ID from ASYS_BINARIES where ROW_ID = '" + vars.get("$local.uid") + "'", SqlUtils.getSystemAlias());
+    db.updateBinary(binaryId, "", bindata, filename, "", "", SqlUtils.getSystemAlias());
 }
\ No newline at end of file
diff --git a/entity/Orderitem_entity/entityfields/quantity/valueProcess.js b/entity/Orderitem_entity/entityfields/quantity/valueProcess.js
index 1eb874ba44..72e8e990de 100644
--- a/entity/Orderitem_entity/entityfields/quantity/valueProcess.js
+++ b/entity/Orderitem_entity/entityfields/quantity/valueProcess.js
@@ -1,10 +1,8 @@
-import("system.vars");
-import("system.result");
-import("system.neon");
-
-if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && !vars.get("$this.value"))
-{
-    result.string("1");
-}
-else
-    result.string(vars.get("$this.value"));
\ No newline at end of file
+import("system.vars");
+import("system.result");
+import("system.neon");
+
+if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$this.value") == null)
+{
+    result.string("1");
+}
\ No newline at end of file
diff --git a/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js b/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js
index 355f0cc560..0dfdf16645 100644
--- a/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Orderitem_entity/recordcontainers/db/onDBUpdate.js
@@ -4,7 +4,7 @@ import("system.neon");
 import("Order_lib");
 import("Sql_lib");
 
-var oid = vars.get("$field.SALESORDER_ID");
+var oid = vars.get("$local.rowdata")["SALESORDERITEM.SALESORDER_ID"];
 if(oid != "")
 {
     var cols = ["NET", "VAT"];
diff --git a/entity/Product_entity/recordcontainers/db/onDBUpdate.js b/entity/Product_entity/recordcontainers/db/onDBUpdate.js
index 11c4f6b2dd..c9c792deeb 100644
--- a/entity/Product_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Product_entity/recordcontainers/db/onDBUpdate.js
@@ -5,7 +5,7 @@ import("Entity_lib");
 // TODO: this is a workaround for missing possibility to react on changes of fields not connected to record Contqainer #1030023
 FieldChanges.assimilateChangeAndDispose("$field.IMAGE", function(state, value){
     if (state == FieldChanges.STATE_CHANGED())
-        ProductUtils.setImage(vars.get("$field.PRODUCTID"), value);
+        ProductUtils.setImage(vars.get("$local.uid"), value);
     else
-        ProductUtils.removeImage(vars.get("$field.PRODUCTID"));
+        ProductUtils.removeImage(vars.get("$local.uid"));
 });
diff --git a/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js b/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js
index 775a8af9d3..44bc3193d9 100644
--- a/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js
@@ -9,31 +9,29 @@ import("KeywordRegistry_basic");
 import("Keyword_lib");
 
 var needToUpdateForecast = null;
+var rowdata = vars.get("$local.rowdata");
 
 // create Milestones if changed
 vars.get("$local.changed").forEach(function(fieldName) {
     var typeValue;
-    var fieldVar;
     var clearReason;
     
     
     switch (fieldName) {
         case "SALESPROJECT.PHASE":
             typeValue = "SalesprojectPhase";
-            fieldVar = "$field.PHASE";
             break;
         case "SALESPROJECT.STATE":
             // Milestone
             typeValue = "SalesprojectState";
-            fieldVar = "$field.STATE";
-            var state = vars.get(fieldVar);
+            var state = rowdata[fieldName];
             // set COMPETITION / OFFER to Lost
             
             // Lost
             if (state == $KeywordRegistry.salesprojectState$lost())
             {
                 // set all offers of the salesproject to lost
-                db.updateData("OFFER", ["STATUS"], null, ["a5682630-01ae-4769-8f03-47dc1db44da4"], SqlCondition.equals("OFFER.OBJECT_ROWID", vars.getString("$field.SALESPROJECTID"), "1=2"));
+                db.updateData("OFFER", ["STATUS"], null, [$KeywordRegistry.offerStatus$lost()], SqlCondition.equals("OFFER.OBJECT_ROWID", vars.getString("$local.uid"), "1=2"));
                 _updateReasons();
                 clearReason = false;
             }
@@ -41,7 +39,7 @@ vars.get("$local.changed").forEach(function(fieldName) {
             else if (state == $KeywordRegistry.salesprojectState$order())
             {
                 // set all competitions of the salesproject to lost
-                db.updateData("COMPETITION", ["STATUS"], null, ["ff73172c-8517-4b6e-98cb-43aebacd9af1"], SqlCondition.equals("COMPETITION.OBJECT_ROWID", vars.getString("$field.SALESPROJECTID"), "1=2"));
+                db.updateData("COMPETITION", ["STATUS"], null, [$KeywordRegistry.competitionState$lost()], SqlCondition.equals("COMPETITION.OBJECT_ROWID", vars.getString("$local.uid"), "1=2"));
                 _updateReasons();
                 clearReason = false;
             }
@@ -50,7 +48,7 @@ vars.get("$local.changed").forEach(function(fieldName) {
             {
                 // do not notify as the user just got a question, if he really would like to clear the forecast
                 needToUpdateForecast = false;
-                db.deleteData("FORECAST", SqlCondition.equals("FORECAST.OBJECT_ROWID", vars.getString("$field.SALESPROJECTID"), "1=2"));
+                db.deleteData("FORECAST", SqlCondition.equals("FORECAST.OBJECT_ROWID", vars.getString("$local.uid"), "1=2"));
             }
             // if state changed, but not to one of the above states
             else
@@ -72,7 +70,7 @@ vars.get("$local.changed").forEach(function(fieldName) {
         if (needToUpdateForecast === null)
             needToUpdateForecast = true;
         
-        Salesproject.insertMilestone(vars.getString("$field.SALESPROJECTID"), typeValue, vars.getString(fieldVar));
+        Salesproject.insertMilestone(vars.getString("$local.uid"), typeValue, vars.getString(fieldVar));
     }
 });
 
@@ -81,13 +79,13 @@ if (needToUpdateForecast)
 
 function _updateReasons()
 {
-    var reasons = vars.getString("field.REASONS");
+    var reasons = rowdata["SALESPROJECT.REASONS"];
     if(reasons)
-        db.updateData("SALESPROJECT", ["REASONS"], null, [reasons], SqlCondition.equals("SALESPROJECT.SALESPROJECTID", vars.getString("$field.SALESPROJECTID"), "1=2"));
+        db.updateData("SALESPROJECT", ["REASONS"], null, [reasons], SqlCondition.equals("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid"), "1=2"));
 }
 
 function _clearReasons(pReallyClear)
 {
     if (pReallyClear)
-        db.updateData("SALESPROJECT", ["REASONS"], null, [""], SqlCondition.equals("SALESPROJECT.SALESPROJECTID", vars.getString("$field.SALESPROJECTID"), "1=2"));
+        db.updateData("SALESPROJECT", ["REASONS"], null, [""], SqlCondition.equals("SALESPROJECT.SALESPROJECTID", vars.getString("$local.uid"), "1=2"));
 }
\ No newline at end of file
diff --git a/process/KeywordRegistry_basic/process.js b/process/KeywordRegistry_basic/process.js
index 6a35b23cbb..572e314759 100644
--- a/process/KeywordRegistry_basic/process.js
+++ b/process/KeywordRegistry_basic/process.js
@@ -121,6 +121,7 @@ $KeywordRegistry.taskProgress = function(){return "TaskProgress";};
 $KeywordRegistry.taskProgress$0 = function(){return $KeywordRegistry._autoPad("TASKPROG0");};
 
 $KeywordRegistry.competitionState = function(){return "CompetitionState";};
+$KeywordRegistry.competitionState$lost = function(){return $KeywordRegistry._autoPad("COMPSTATELOST");};
 $KeywordRegistry.objectRelationType = function(){return "ObjectRelationType";};
 $KeywordRegistry.deliveryTerm = function(){return "DeliveryTerm";};
 $KeywordRegistry.paymentTerm = function(){return "PaymentTerm";};
-- 
GitLab