From c71d9a7b2a22b452d7ba6d7af9f43e4020dcd107 Mon Sep 17 00:00:00 2001
From: Daniel Tran <d.tran@adito.de>
Date: Tue, 26 May 2020 12:44:22 +0200
Subject: [PATCH] #1050274: Added mandatory process to prevent addresses
 without corresponding contact.

---
 entity/QuickEntry_entity/QuickEntry_entity.aod         |  4 ++++
 .../entityfields/lastname/mandatoryProcess.js          | 10 ++++++++++
 .../entityfields/person_salutation/mandatoryProcess.js | 10 ++++++++++
 3 files changed, 24 insertions(+)
 create mode 100644 entity/QuickEntry_entity/entityfields/lastname/mandatoryProcess.js
 create mode 100644 entity/QuickEntry_entity/entityfields/person_salutation/mandatoryProcess.js

diff --git a/entity/QuickEntry_entity/QuickEntry_entity.aod b/entity/QuickEntry_entity/QuickEntry_entity.aod
index 3a754cdb58..953caf6950 100644
--- a/entity/QuickEntry_entity/QuickEntry_entity.aod
+++ b/entity/QuickEntry_entity/QuickEntry_entity.aod
@@ -67,10 +67,13 @@
     <entityField>
       <name>FIRSTNAME</name>
       <title>Firstname</title>
+      <mandatoryProcess>%aditoprj%/entity/QuickEntry_entity/entityfields/firstname/mandatoryProcess.js</mandatoryProcess>
     </entityField>
     <entityField>
       <name>LASTNAME</name>
       <title>Lastname</title>
+      <mandatoryProcess>%aditoprj%/entity/QuickEntry_entity/entityfields/lastname/mandatoryProcess.js</mandatoryProcess>
+      <valueProcess>%aditoprj%/entity/QuickEntry_entity/entityfields/lastname/valueProcess.js</valueProcess>
     </entityField>
     <entityField>
       <name>PERSON_TITLE</name>
@@ -81,6 +84,7 @@
       <name>PERSON_SALUTATION</name>
       <title>Salutation</title>
       <consumer>Salutations</consumer>
+      <mandatoryProcess>%aditoprj%/entity/QuickEntry_entity/entityfields/person_salutation/mandatoryProcess.js</mandatoryProcess>
     </entityField>
     <entityField>
       <name>PERSON_CONTACT_ID</name>
diff --git a/entity/QuickEntry_entity/entityfields/lastname/mandatoryProcess.js b/entity/QuickEntry_entity/entityfields/lastname/mandatoryProcess.js
new file mode 100644
index 0000000000..c5a419766d
--- /dev/null
+++ b/entity/QuickEntry_entity/entityfields/lastname/mandatoryProcess.js
@@ -0,0 +1,10 @@
+import("system.logging");
+import("system.result");
+import("system.vars");
+
+var insertedRows = vars.get("$field.Adresses.insertedRows");
+var isInserted = insertedRows.some(function (row){
+    return row["ZIP"] || row["CITY"] || row["ADDRESS"];
+})
+
+result.string(isInserted);
\ No newline at end of file
diff --git a/entity/QuickEntry_entity/entityfields/person_salutation/mandatoryProcess.js b/entity/QuickEntry_entity/entityfields/person_salutation/mandatoryProcess.js
new file mode 100644
index 0000000000..c5a419766d
--- /dev/null
+++ b/entity/QuickEntry_entity/entityfields/person_salutation/mandatoryProcess.js
@@ -0,0 +1,10 @@
+import("system.logging");
+import("system.result");
+import("system.vars");
+
+var insertedRows = vars.get("$field.Adresses.insertedRows");
+var isInserted = insertedRows.some(function (row){
+    return row["ZIP"] || row["CITY"] || row["ADDRESS"];
+})
+
+result.string(isInserted);
\ No newline at end of file
-- 
GitLab