From a0b7dd9bbf5bc162a15488a74cda0ff5594ad1f5 Mon Sep 17 00:00:00 2001
From: Johannes Hoermann <j.hoermann@adito.de>
Date: Wed, 20 Nov 2019 10:06:37 +0100
Subject: [PATCH] Fix lead import

---
 entity/ImportField_Entity/ImportField_Entity.aod | 1 +
 process/Leadimport_lib/process.js                | 4 ++--
 process/importLead_serverProcess/process.js      | 8 ++++----
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/entity/ImportField_Entity/ImportField_Entity.aod b/entity/ImportField_Entity/ImportField_Entity.aod
index c10aa10b61..c9a4484e4b 100644
--- a/entity/ImportField_Entity/ImportField_Entity.aod
+++ b/entity/ImportField_Entity/ImportField_Entity.aod
@@ -42,6 +42,7 @@
     <entityField>
       <name>FIELDNAME</name>
       <title>Fieldname</title>
+      <state>READONLY</state>
     </entityField>
     <entityConsumer>
       <name>LeadImportC</name>
diff --git a/process/Leadimport_lib/process.js b/process/Leadimport_lib/process.js
index 857d35cf48..e4f727e01e 100644
--- a/process/Leadimport_lib/process.js
+++ b/process/Leadimport_lib/process.js
@@ -520,7 +520,7 @@ LeadImportUtils.insertOrg = function(pDataFields, pDataTypes,  pFieldDef, pField
 */
 LeadImportUtils.insertPers = function(pDataFields, pDataTypes,  pFieldDef, pFieldValues, pOrgId, pLeadValues, pUser, pDate)
 {
-    var isoLanguage = checkISOLanguage(pLeadValues["ISOLANGUAGE"]);
+    var isoLanguage = LeadImportUtils.checkISOLanguage(pLeadValues["ISOLANGUAGE"]);
     //Person
     var PersValues = LeadImportUtils.setValues(pDataFields["PERSON"], pFieldDef, pFieldValues);
     PersValues["TITLE"] = ContactInfoUtils.getTitle(pLeadValues, isoLanguage);
@@ -553,7 +553,7 @@ LeadImportUtils.insertPers = function(pDataFields, pDataTypes,  pFieldDef, pFiel
     AddrValues["CONTACT_ID"] = contactId;
     LeadImportUtils.insertTable(pDataFields, pDataTypes, AddrValues, "ADDRESS", pUser, pDate);
 
-    var entityFieldValues = getEntityFieldsPers(PersValues, ContactValues, AddrValues);
+    var entityFieldValues = LeadImportUtils.getEntityFieldsPers(PersValues, ContactValues, AddrValues);
     
     return new Array(persid, contactId, entityFieldValues);
 }
diff --git a/process/importLead_serverProcess/process.js b/process/importLead_serverProcess/process.js
index bde3d74c07..a6807e2297 100644
--- a/process/importLead_serverProcess/process.js
+++ b/process/importLead_serverProcess/process.js
@@ -33,11 +33,11 @@ data = util.decodeBase64String(data);
 data = text.parseCSV(data.replace(/(^\s+)|(\s+$)/g,""), recordSep, fieldSep, fieldLimit.charAt(0));//get data from file
 
 var ImportDate =  vars.getString("$sys.date");
-var ImportFieldDef = getImportFieldDef(importdefid); // [Fieldnumber, Mappingfield]
+var ImportFieldDef = LeadImportUtils.getImportFieldDef(importdefid); // [Fieldnumber, Mappingfield]
 
 var DataFieldCount = data[0].length;
 //  Attributes that should be created for Organisations and persons
-var AttrObject = getLeadAttr(importdefid);
+var AttrObject = LeadImportUtils.getLeadAttr(importdefid);
 
 var FieldDef = LeadImportUtils.addArray(ImportFieldDef, new Array(DataFieldCount++, "SOURCE", ""));
 
@@ -123,7 +123,7 @@ try
         var countrypos = getFieldPos (FieldDef, "COUNTRY")[0];
         
         //check the COUNTRY
-        impvalues[countrypos] = checkCountry(impvalues[countrypos]);
+        impvalues[countrypos] = LeadImportUtils.checkCountry(impvalues[countrypos]);
         
         try//import data
         {
@@ -146,7 +146,7 @@ catch(err)
     logging.log(err);
 }
 
-scanLeadDups(allContactData);//search for duplicates
+LeadImportUtils.scanLeadDups(allContactData);//search for duplicates
 
 var rows = eMath.subInt(dsanz, 1);
 rows = eMath.subInt(rows, errorCount);//datasetcount - errors = inserts
-- 
GitLab