From 5b3cd7cd4296776247aeeb441ff67c7031f78e51 Mon Sep 17 00:00:00 2001
From: "b.ulrich" <b.ulrich@adito.de>
Date: Tue, 27 Jul 2021 15:15:05 +0200
Subject: [PATCH] =?UTF-8?q?[Projekt:=20xRM-Sales][TicketNr.:=201084745][In?=
 =?UTF-8?q?konsistente=20Anlage=20von=20SALESPROJECT=5FMILESTONE-Datens?=
 =?UTF-8?q?=C3=A4tzen]?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../recordcontainers/db/onDBUpdate.js                | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js b/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js
index c9dfa3fa5c..ad790b8768 100644
--- a/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Salesproject_entity/recordcontainers/db/onDBUpdate.js
@@ -1,3 +1,4 @@
+import("system.datetime");
 import("Workflow_lib");
 import("Context_lib");
 import("system.neon");
@@ -22,6 +23,7 @@ vars.get("$local.changed").forEach(function(fieldName) {
     
     switch (fieldName) {
         case "SALESPROJECT.PHASE":
+            typeValue = "SalesprojectPhase";
             break;
         case "SALESPROJECT.STATUS":
             // Milestone
@@ -97,6 +99,16 @@ vars.get("$local.changed").forEach(function(fieldName) {
     }
 });
 
+if(rowdata["SALESPROJECT.STATUS"] == $KeywordRegistry.salesprojectState$aborted()
+    || rowdata["SALESPROJECT.STATUS"] == $KeywordRegistry.salesprojectState$partialOrder()
+    || rowdata["SALESPROJECT.STATUS"] == $KeywordRegistry.salesprojectState$order()
+    || rowdata["SALESPROJECT.STATUS"] == $KeywordRegistry.salesprojectState$lost())
+{
+    newWhere("SALESPROJECT_MILESTONE.SALESPROJECT_ID", "$local.uid")
+    .and("SALESPROJECT_MILESTONE.DATE_END is null")
+    .and("SALESPROJECT_MILESTONE.KIND", "SalesprojectPhase").updateData(true, "SALESPROJECT_MILESTONE", ["DATE_END"], null, [datetime.date()]);
+}
+
 var [serviceUrl, channelId] = newSelect(["SERVICE_URL", "GENERAL_CHANNELID"])
     .from("MST_TEAM")
     .where("MST_TEAM.MST_TEAMID", "$field.MST_TEAM_ID")
-- 
GitLab