From 5d932395ed6ec8119dfc5e03a5e603a9d05c467d Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Wed, 3 Jul 2019 16:44:56 +0200
Subject: [PATCH] Update First-/Lastname of employee if Person name changed

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

diff --git a/entity/Person_entity/recordcontainers/db/onDBUpdate.js b/entity/Person_entity/recordcontainers/db/onDBUpdate.js
index 558fad5fb3..8c54172f7f 100644
--- a/entity/Person_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/Person_entity/recordcontainers/db/onDBUpdate.js
@@ -1,3 +1,4 @@
+import("system.tools");
 import("system.vars");
 import("Person_lib");
 import("Communication_lib");
@@ -15,4 +16,19 @@ FieldChanges.assimilateChangeAndDispose("$field.STANDARD_PHONE_COMMUNICATION", f
 });
 
 new StandardObject("Address", vars.get("$field.ADDRESS_ID"), "Person", vars.get("$field.CONTACTID"))
-    .onPersonUpdate(vars.get("$field.ORGANISATION_ID"));
\ No newline at end of file
+    .onPersonUpdate(vars.get("$field.ORGANISATION_ID"));
+
+var updates = [];
+    
+// update user object if name changed
+vars.get("$local.changed").forEach(function(fieldName) {
+    switch (fieldName) {
+        case "PERSON.FIRSTNAME":
+        case "PERSON.LASTNAME":
+            var user = tools.getUserByAttribute(tools.CONTACTID, [vars.get("$field.CONTACTID")], tools.PROFILE_FULL);
+            user[tools.PARAMS][tools.FIRSTNAME] = vars.get("$field.FIRSTNAME");
+            user[tools.PARAMS][tools.LASTNAME] = vars.get("$field.LASTNAME");
+            tools.updateUser(user);
+            break;
+    }
+})
\ No newline at end of file
-- 
GitLab