From 225f8ee7d436edff802c5668b72df439ddc63b3f Mon Sep 17 00:00:00 2001
From: Daniel Tran <d.tran@adito.de>
Date: Thu, 7 May 2020 15:56:46 +0200
Subject: [PATCH] #1057408: Fixed bug.

---
 .../AddressValidation_entity.aod              |  6 ++++
 .../QuickEntry_entity/QuickEntry_entity.aod   |  8 +++++
 .../leadquickacquisition/onValueChange.js     | 34 +++++++++++++++++--
 3 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/entity/AddressValidation_entity/AddressValidation_entity.aod b/entity/AddressValidation_entity/AddressValidation_entity.aod
index d3842d9a8e..3d3c7ba01a 100644
--- a/entity/AddressValidation_entity/AddressValidation_entity.aod
+++ b/entity/AddressValidation_entity/AddressValidation_entity.aod
@@ -106,6 +106,12 @@
           <fieldName>FullAddressValidation</fieldName>
           <isConsumer v="false" />
         </entityDependency>
+        <entityDependency>
+          <name>4301c0b9-401f-43af-bd21-8a034aaa7d55</name>
+          <entityName>QuickEntry_entity</entityName>
+          <fieldName>AdressValidation</fieldName>
+          <isConsumer v="false" />
+        </entityDependency>
       </dependencies>
       <children>
         <entityParameter>
diff --git a/entity/QuickEntry_entity/QuickEntry_entity.aod b/entity/QuickEntry_entity/QuickEntry_entity.aod
index 3a754cdb58..57fc14ed25 100644
--- a/entity/QuickEntry_entity/QuickEntry_entity.aod
+++ b/entity/QuickEntry_entity/QuickEntry_entity.aod
@@ -224,6 +224,14 @@
       <stateProcess>%aditoprj%/entity/QuickEntry_entity/entityfields/leadquickacquisition/stateProcess.js</stateProcess>
       <onValueChange>%aditoprj%/entity/QuickEntry_entity/entityfields/leadquickacquisition/onValueChange.js</onValueChange>
     </entityField>
+    <entityConsumer>
+      <name>AdressValidation</name>
+      <dependency>
+        <name>dependency</name>
+        <entityName>AddressValidation_entity</entityName>
+        <fieldName>FullAddressValidation</fieldName>
+      </dependency>
+    </entityConsumer>
   </entityFields>
   <recordContainers>
     <jDitoRecordContainer>
diff --git a/entity/QuickEntry_entity/entityfields/leadquickacquisition/onValueChange.js b/entity/QuickEntry_entity/entityfields/leadquickacquisition/onValueChange.js
index c6d127a513..70cc939534 100644
--- a/entity/QuickEntry_entity/entityfields/leadquickacquisition/onValueChange.js
+++ b/entity/QuickEntry_entity/entityfields/leadquickacquisition/onValueChange.js
@@ -1,6 +1,7 @@
 import("system.neon");
 import("system.vars");
 import("Entity_lib");
+import("system.entities");
 import("KeywordRegistry_basic");
 import("LeadQuickAcquisition_lib");
 
@@ -37,9 +38,38 @@ if(vars.get("$local.value"))
         }
         else if(response.address)
         {
-            neon.addRecord("OrgAddresses", {
+            var orgAddressPresets = {
                 "AddressSearch" : response.address
-            });
+            };
+            
+            var getRowsConfig = entities.createConfigForLoadingRows()
+                                            .entity("AddressValidation_entity")
+                                            .provider("FullAddressValidation")
+                                            .fields(["CITY", "ZIP", "STREET"])
+                                            .addParameter("CurrentValue_param", "Ritter-von-Schoch-Straße 5, 84036 Landshut");
+                
+            var rows = entities.getRows(getRowsConfig);
+            
+            if (rows.length > 0)
+            {
+                var affectedRow = rows[0];
+                
+                if (affectedRow["CITY"])
+                    orgAddressPresets.CITY = affectedRow["CITY"];
+                
+                if (affectedRow["ZIP"]) 
+                {
+                    orgAddressPresets.ZIP = affectedRow["ZIP"];
+                }
+                
+                if (affectedRow["STREET"])
+                {
+                    orgAddressPresets.ADDRESS = affectedRow["STREET"];
+                }
+                
+            }
+            
+            neon.addRecord("OrgAddresses", orgAddressPresets);
         }
         
         if(response.companyName) neon.setFieldValue("$field.ORGANISATION_NAME", response.companyName);
-- 
GitLab