From dd8449f2f55d49c317babfa5e6b28ea792aa3d8a Mon Sep 17 00:00:00 2001
From: "d.buechler" <d.buechler@adito.de>
Date: Tue, 30 Apr 2019 11:59:54 +0200
Subject: [PATCH] Fixed bug where the default campaignStep wasnt auto selected
 Now the CampaignParticipantLog gets updated correctly

---
 .../entityfields/campaign_id/onValueChange.js              | 4 +---
 .../entityfields/campaignstep_id/displayValueProcess.js    | 1 -
 .../recordcontainers/jdito/onInsert.js                     | 7 +++++--
 process/Campaign_lib/process.js                            | 3 +--
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/entity/CampaignAddParticipants_entity/entityfields/campaign_id/onValueChange.js b/entity/CampaignAddParticipants_entity/entityfields/campaign_id/onValueChange.js
index a8754300a5e..45222625e11 100644
--- a/entity/CampaignAddParticipants_entity/entityfields/campaign_id/onValueChange.js
+++ b/entity/CampaignAddParticipants_entity/entityfields/campaign_id/onValueChange.js
@@ -1,9 +1,7 @@
-import("system.logging");
 import("system.vars");
 import("system.neon");
 import("Campaign_lib");
 
 var stepId;
-CampaignUtils.getDefaultCampaignStep(vars.get("$field.CAMPAIGN_ID"));
-
+stepId = CampaignUtils.getDefaultCampaignStep(vars.get("$field.CAMPAIGN_ID"));
 neon.setFieldValue("$field.CAMPAIGNSTEP_ID", stepId);
\ No newline at end of file
diff --git a/entity/CampaignAddParticipants_entity/entityfields/campaignstep_id/displayValueProcess.js b/entity/CampaignAddParticipants_entity/entityfields/campaignstep_id/displayValueProcess.js
index 649caa2bc64..42912a8480c 100644
--- a/entity/CampaignAddParticipants_entity/entityfields/campaignstep_id/displayValueProcess.js
+++ b/entity/CampaignAddParticipants_entity/entityfields/campaignstep_id/displayValueProcess.js
@@ -1,4 +1,3 @@
-import("system.logging");
 import("system.vars");
 import("Campaign_lib");
 import("system.result");
diff --git a/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js b/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
index cadda267735..109ef8e54dc 100644
--- a/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
+++ b/entity/CampaignAddParticipants_entity/recordcontainers/jdito/onInsert.js
@@ -36,6 +36,7 @@ else
 }
 
 var statementArray = [];
+var logArray = [];
 logging.log("isUpdate -> " + isUpdate);
 for (participant in participants)
 {
@@ -51,7 +52,7 @@ for (participant in participants)
         let valsCampaignParticipantLog = new Array(participants[participant], campaignId, newCampaignStepId, campaignParticipantLogId, vars.get("$sys.user"), vars.get("$sys.date"));
         
         statementArray.push(["CAMPAIGNPARTICIPANT", cols, null, updatedValues, condition]);
-        statementArray.push(["CAMPAIGNPARTICIPANTLOG", colNamesCampaignParticipantLog, null, valsCampaignParticipantLog]);
+        logArray.push(["CAMPAIGNPARTICIPANTLOG", colNamesCampaignParticipantLog, null, valsCampaignParticipantLog]);
     }
     else
     {
@@ -68,7 +69,7 @@ for (participant in participants)
         let valsCampaignParticipantLog = new Array(campaignParticipantId, campaignId, newCampaignStepId, campaignParticipantLogId, vars.get("$sys.user"), vars.get("$sys.date"));
 
         statementArray.push(["CAMPAIGNPARTICIPANT", cols, null, valsCampaignParticipant]);
-        statementArray.push(["CAMPAIGNPARTICIPANTLOG", colNamesCampaignParticipantLog, null, valsCampaignParticipantLog]);
+        logArray.push(["CAMPAIGNPARTICIPANTLOG", colNamesCampaignParticipantLog, null, valsCampaignParticipantLog]);
     }
 }
 
@@ -76,3 +77,5 @@ if(isUpdate == "true")
     db.updates(statementArray)
 else
     db.inserts(statementArray);
+
+db.inserts(logArray);
\ No newline at end of file
diff --git a/process/Campaign_lib/process.js b/process/Campaign_lib/process.js
index 583e4b54a79..fc875f9b777 100644
--- a/process/Campaign_lib/process.js
+++ b/process/Campaign_lib/process.js
@@ -166,8 +166,7 @@ CampaignUtils.getDefaultCampaignStep = function(pCampaignId)
 {
     let selectQuery = "select CAMPAIGNSTEPID from CAMPAIGNSTEP " +
                       "where CAMPAIGNSTEP.CAMPAIGN_ID = '" + pCampaignId + "' " +
-                      "order by CAMPAIGNSTEP.SORTING asc " +
-                      "fetch first 1 rows only";
+                      "order by CAMPAIGNSTEP.SORTING asc";
     
     
     return db.cell(selectQuery)   
-- 
GitLab