From df6c05182cc618699f1442ff5f33db848a9a81f1 Mon Sep 17 00:00:00 2001
From: Benjamin Ulrich <b.ulrich@adito.de>
Date: Wed, 14 Oct 2020 13:10:48 +0000
Subject: [PATCH] [Projekt: Entwicklung - Neon][TicketNr.:
 1060551][Standardadresse bleibt bei Firmenwechsel gleich]

---
 .../recordcontainers/db/onDBUpdate.js         | 26 +++----------------
 1 file changed, 3 insertions(+), 23 deletions(-)

diff --git a/entity/Person_entity/recordcontainers/db/onDBUpdate.js b/entity/Person_entity/recordcontainers/db/onDBUpdate.js
index b6e1ccbb97b..0c29899fd43 100644
--- a/entity/Person_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Person_entity/recordcontainers/db/onDBUpdate.js
@@ -21,30 +21,10 @@ for (var i = 0; i < localChanged.length; i++) {
 
 if(orgChanged)
 {
-    var orgAddressId = newSelect("CONTACT.ADDRESS_ID")
-                                    .from("CONTACT")
-                                    .where("CONTACT.ORGANISATION_ID",  vars.get("$field.ORGANISATION_ID"))
-                                    .and("CONTACT.PERSON_ID is null")
-                                    .cell();
+    var standardAddressId = new StandardObject("Address", null, "Person", vars.get("$field.PERSONID"))
+            .onPersonValueChange(vars.get("$field.ORGANISATION_ID"));
 
-    var addressId = vars.get("$field.ADDRESS_ID");
-
-    if(addressId != orgAddressId) //update standard address if the the organisation changed
-    {
-        var persAddress = newSelect("ADDRESS.ADDRESSID")
-                                .from("ADDRESS")
-                                .where("ADDRESS.CONTACT_ID", vars.get("$field.CONTACTID"))
-                                .and("ADDRESS.ADDRESSID", addressId)
-                                .cell();
-
-        if(!persAddress) // only when the standard address is from the organisation
-        {
-            var standardAddressId = new StandardObject("Address", null, "Person", vars.get("$field.PERSONID"))
-                    .onPersonValueChange(vars.get("$field.ORGANISATION_ID"));
-
-            neon.setFieldValue("$field.ADDRESS_ID", standardAddressId);
-        }
-    }
+    newWhere("CONTACT.CONTACTID", vars.get("$field.CONTACTID")).updateData(true, "CONTACT", ["ADDRESS_ID"], null, [standardAddressId])
 }
 
 var rowdata =  vars.get("$local.rowdata");
-- 
GitLab