From a937dd26dd51165749137ad33e7e9773b5c54b72 Mon Sep 17 00:00:00 2001
From: "s.pongratz" <s.pongratz@adito.de>
Date: Tue, 2 Feb 2021 11:45:38 +0100
Subject: [PATCH] #1071012-LedimportStandartadresse Organisation Address is set
 as main Address in the contact

---
 process/Leadimport_lib/process.js | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/process/Leadimport_lib/process.js b/process/Leadimport_lib/process.js
index 422506bef5..f651e47b33 100644
--- a/process/Leadimport_lib/process.js
+++ b/process/Leadimport_lib/process.js
@@ -163,14 +163,15 @@ LeadImportUtils.importData = function(pDataFields, pDataTypes, pFieldDef, pField
     var orgObjID = "";  
     var orgsForDubCheck = "";
     var persForDubCheck = "";
-    var orgRet;
+    var orgAddressID = null;
+    var orgRet = [null, null, null, null];
     var persRet;
     
     //------create organisation
     if (LeadValues["NAME"].trim() != "")//only if Organame is filled
     {
         orgObjID = "Organisation";//for attribute
-        orgRet = LeadImportUtils.insertOrg(pDataFields, pDataTypes,  pFieldDef, pFieldValues, pUser, pDate);
+        [orgRet[0], orgRet[1], orgRet[2], orgRet[3], orgAddressID] = LeadImportUtils.insertOrg(pDataFields, pDataTypes,  pFieldDef, pFieldValues, pUser, pDate);
 
         orgid = orgRet[0];
         orgContactId = orgRet[1];
@@ -186,7 +187,7 @@ LeadImportUtils.importData = function(pDataFields, pDataTypes, pFieldDef, pField
     if (LeadValues["LASTNAME"].trim() != "")//only if lastname is filled
     {
         persObjID = "Person";//for attribute
-        persRet = LeadImportUtils.insertPers(pDataFields, pDataTypes,  pFieldDef, pFieldValues, orgid, LeadValues, pUser, pDate);
+        persRet = LeadImportUtils.insertPers(pDataFields, pDataTypes,  pFieldDef, pFieldValues, orgid, LeadValues, pUser, pDate, orgAddressID);
         
         persid = persRet[0];
         persContactId = persRet[1];
@@ -574,11 +575,11 @@ LeadImportUtils.insertOrg = function(pDataFields, pDataTypes,  pFieldDef, pField
             workflow.startProcessByKey("leadprocess", processVariables)
         }
         
-        return new Array(orgid, contactId ,entityFieldValues, true);
+        return new Array(orgid, contactId ,entityFieldValues, true, ContactValues["ADDRESS_ID"]);
     }
     //return the ids of the existing organisation so that people who work for the same organisation are assigned to them
     //               OrgId  ContactID 
-    return new Array(ids[0], ids[1] ,entityFieldValues, false);
+    return new Array(ids[0], ids[1] ,entityFieldValues, false, ids[2]);
 }
 
 /**
@@ -595,7 +596,7 @@ LeadImportUtils.insertOrg = function(pDataFields, pDataTypes,  pFieldDef, pField
  *
  * @return {String []} (personId, contactId, duplicateMapping)
  */
-LeadImportUtils.insertPers = function(pDataFields, pDataTypes,  pFieldDef, pFieldValues, pOrgId, pLeadValues, pUser, pDate)
+LeadImportUtils.insertPers = function(pDataFields, pDataTypes,  pFieldDef, pFieldValues, pOrgId, pLeadValues, pUser, pDate, pOrgAddressID)
 {
     var isoLanguage = pLeadValues["ISOLANGUAGE"];
     
@@ -611,7 +612,6 @@ LeadImportUtils.insertPers = function(pDataFields, pDataTypes,  pFieldDef, pFiel
 
     ContactValues["STATUS"] = "CONTACTSTATACTIVE";//only insert active persons
     ContactValues["PERSON_ID"] = persid;
-    ContactValues["ADDRESS_ID"] = util.getNewUUID();
     ContactValues["DEPARTMENT"] = ContactInfoUtils.getContactDepartment(pLeadValues);
     ContactValues["CONTACTROLE"] = ContactInfoUtils.getContactRole(pLeadValues);
     ContactValues["CONTACTPOSITION"] = ContactInfoUtils.getContactPosition(pLeadValues);
@@ -624,14 +624,14 @@ LeadImportUtils.insertPers = function(pDataFields, pDataTypes,  pFieldDef, pFiel
     else
     {
         ContactValues["ORGANISATION_ID"] = pOrgId;
-        ContactValues["ADDRESS_ID"] = 0
+        ContactValues["ADDRESS_ID"] = pOrgAddressID
     }
         
     
     var contactId =  LeadImportUtils.insertTable(pDataFields, pDataTypes, ContactValues, "CONTACT", pUser, pDate);
     
     //Address
-    if (ContactValues["ADDRESS_ID"])
+    if (ContactValues["ADDRESS_ID"] && !ContactValues["ORGANISATION_ID"])
     {
         var AddrValues = LeadImportUtils.setValues(pDataFields["ADDRESS"], pFieldDef, pFieldValues);
         AddrValues["ADDRESSID"] = ContactValues["ADDRESS_ID"];
@@ -954,7 +954,7 @@ LeadImportUtils.scanLeadDups = function(pAllContactData)
 LeadImportUtils.checkOrgDup = function(pLeadValues)
 {
     //  search whether the organisation already exists        
-    var query = newSelect("ORGANISATIONID, CONTACTID")
+    var query = newSelect(["ORGANISATIONID, CONTACTID, ADDRESSID"])
                 .from("ORGANISATION")
                 .join("CONTACT", "ORGANISATIONID = CONTACT.ORGANISATION_ID")
                 .join("ADDRESS", "ADDRESSID = ADDRESS_ID");
-- 
GitLab