diff --git a/process/Leadimport_lib/process.js b/process/Leadimport_lib/process.js index 79b550f399b4ac68d9fdbc4f3e65f4d918703add..426169387e80b326d5582bd0f118385fac25e6c5 100644 --- a/process/Leadimport_lib/process.js +++ b/process/Leadimport_lib/process.js @@ -153,9 +153,6 @@ LeadImportUtils.loadImportFile = function(pBinId, pFieldSep, pFieldLimit, pRecor */ LeadImportUtils.importData = function(pDataFields, pDataTypes, pFieldDef, pFieldValues, pImportDefID, pAttrObject, pSource, pUser, pDate) { - // set the mappings - LeadImportUtils.mapping = LeadImportUtils.getMapping(pImportDefID); - var LeadValues = LeadImportUtils.setValues(pDataFields["LEAD"], pFieldDef, pFieldValues); // set the Lead values var orgid = ""; @@ -329,13 +326,7 @@ LeadImportUtils.setValues = function(pFields, pFieldDef, pFieldValues) { if (pFieldValues[ pFieldDef[i][0]] != undefined) { - if (LeadImportUtils.mapping != undefined && - LeadImportUtils.mapping[pFieldDef[i][1]] != undefined && - LeadImportUtils.mapping[pFieldDef[i][1]][pFieldValues[pFieldDef[i][0]]] != undefined) - { - // mapping is available and is set - pFieldValues[pFieldDef[i][0]] = LeadImportUtils.mapping[pFieldDef[i][1]][pFieldValues[pFieldDef[i][0]]]; - } + pFieldValues[pFieldDef[i][0]] = LeadImportUtils.getMappedOutputvalue(pFieldDef[i][1], pFieldValues[pFieldDef[i][0]]); dataValues[pFieldDef[i][1]] = pFieldValues[pFieldDef[i][0]]; } @@ -348,6 +339,26 @@ LeadImportUtils.setValues = function(pFields, pFieldDef, pFieldValues) return dataValues; } +/** + * Get the mapped outputvalue of the inputvalue. + * Thes are the mapping of the mapping-tab in the Leadimport + * + * @param {String} pField field + * @param {String} pInputValue import values + * + * @return {String} outputvalue + */ +LeadImportUtils.getMappedOutputvalue = function (pField, pInputValue) { + if (LeadImportUtils.mapping != undefined && + LeadImportUtils.mapping[pField] != undefined && + LeadImportUtils.mapping[pField][pInputValue] != undefined) + { + // mapping is available and is set + return LeadImportUtils.mapping[pField][pInputValue]; + } + return pInputValue; +} + /** * returns import fields * @@ -580,7 +591,8 @@ LeadImportUtils.insertOrg = function(pDataFields, pDataTypes, pFieldDef, pField */ LeadImportUtils.insertPers = function(pDataFields, pDataTypes, pFieldDef, pFieldValues, pOrgId, pLeadValues, pUser, pDate) { - var isoLanguage = LeadImportUtils.checkISOLanguage(pLeadValues["ISOLANGUAGE"]); + var isoLanguage = pLeadValues["ISOLANGUAGE"] ? pLeadValues["ISOLANGUAGE"] : "deu"; + //Person var PersValues = LeadImportUtils.setValues(pDataFields["PERSON"], pFieldDef, pFieldValues); PersValues["TITLE"] = ContactInfoUtils.getTitle(pLeadValues, isoLanguage); @@ -597,7 +609,6 @@ LeadImportUtils.insertPers = function(pDataFields, pDataTypes, pFieldDef, pFiel ContactValues["DEPARTMENT"] = ContactInfoUtils.getContactDepartment(pLeadValues); ContactValues["CONTACTROLE"] = ContactInfoUtils.getContactRole(pLeadValues); ContactValues["CONTACTPOSITION"] = ContactInfoUtils.getContactPosition(pLeadValues); - ContactValues["CONTACTPOSITION"] = ContactInfoUtils.getContactPosition(pLeadValues); if (pOrgId == "")//private ContactValues["ORGANISATION_ID"] = 0; @@ -1024,17 +1035,7 @@ function ContactInfoUtils() {} */ ContactInfoUtils.getContactDepartment = function(pLeadValues) { - if (pLeadValues["DEPARTMENT"] != undefined && pLeadValues["DEPARTMENT"] != "") - { - var department = KeywordUtils.getEntryNamesByContainer("ContactDepartment"); - - for (let i = 0; i < department.length; i++) - { - if (pLeadValues["DEPARTMENT"].trim() == department[i].trim()) - return department[i]; - } - } - return ""; + return ContactInfoUtils.getEntryNameByContainerAndFieldValue("ContactDepartment", pLeadValues["DEPARTMENT"]); }; /** @@ -1046,17 +1047,7 @@ ContactInfoUtils.getContactDepartment = function(pLeadValues) */ ContactInfoUtils.getContactPosition = function(pLeadValues) { - if (pLeadValues["CONTACTPOSITION"] != undefined && pLeadValues["CONTACTPOSITION"] != "") - { - var position = KeywordUtils.getEntryNamesByContainer("ContactPosition"); - - for (let i = 0; i < position.length; i++) - { - if (pLeadValues["CONTACTPOSITION"].trim() == position[i].trim()) - return position[i]; - } - } - return ""; + return ContactInfoUtils.getEntryNameByContainerAndFieldValue("ContactPosition", pLeadValues["CONTACTPOSITION"]); }; /** @@ -1068,17 +1059,7 @@ ContactInfoUtils.getContactPosition = function(pLeadValues) */ ContactInfoUtils.getContactRole = function(pLeadValues) { - if (pLeadValues["CONTACTROLE"] != undefined && pLeadValues["CONTACTROLE"] != "") - { - var role = KeywordUtils.getEntryNamesByContainer("ContactContactrole"); - - for (let i = 0; i < role.length; i++) - { - if (pLeadValues["CONTACTROLE"].trim() == role[i].trim()) - return role[i]; - } - } - return ""; + return ContactInfoUtils.getEntryNameByContainerAndFieldValue("ContactContactrole", pLeadValues["CONTACTROLE"]); }; /** @@ -1090,14 +1071,27 @@ ContactInfoUtils.getContactRole = function(pLeadValues) */ ContactInfoUtils.getGender = function(pLeadValues) { - if (pLeadValues["GENDER"] != undefined && pLeadValues["GENDER"] != "") + return ContactInfoUtils.getEntryNameByContainerAndFieldValue("PersonGender", pLeadValues["GENDER"]); +}; + +/** + * Gets the keyword value if it is set and it is a correct value + * + * @param {Object} pContainerName the name of the KeywordContainer; + * @param {Object} pFieldValue the value of the field for the keyword; + * + * @return {String} the keywordvalue + */ +ContactInfoUtils.getEntryNameByContainerAndFieldValue = function(pContainerName, pFieldValue) +{ + if (pFieldValue != undefined && pFieldValue != "") { - var gender = KeywordUtils.getEntryNamesByContainer("PersonGender"); + let keyword = KeywordUtils.getEntryNamesAndIdsByContainer(pContainerName); - for (let i = 0; i < gender.length; i++) + for (let i = 0; i < keyword.length; i++) { - if (pLeadValues["GENDER"].trim() == gender[i].trim()) - return gender[i]; + if (pFieldValue.trim() == keyword[i][0].trim() || pFieldValue.trim() == keyword[i][1].trim()) + return keyword[i][1]; } } return ""; diff --git a/process/importLead_serverProcess/process.js b/process/importLead_serverProcess/process.js index 726b33579a7c3aeac476e8fb75698444fcbc873c..a24b084a933769d7e6d3ab8b6b1d316828841452 100644 --- a/process/importLead_serverProcess/process.js +++ b/process/importLead_serverProcess/process.js @@ -68,6 +68,9 @@ var posOrginfo = getFieldPos(ImportFieldDef, "INFO"); // Data without headline var dsanz = 1; +// set the mappings +LeadImportUtils.mapping = LeadImportUtils.getMapping(importdefid); + try { @@ -125,6 +128,15 @@ try //check the COUNTRY impvalues[countrypos] = LeadImportUtils.checkCountry(impvalues[countrypos]); + if (!(getFieldPos(ImportFieldDef, "ISOLANGUAGE").length == 0)){ + //get the position of the ISOLANGUAGE + var isolanguepos = getFieldPos (FieldDef, "ISOLANGUAGE")[0]; + + //mapp and check the ISOLANGUAGE + impvalues[isolanguepos] = LeadImportUtils.getMappedOutputvalue("ISOLANGUAGE", impvalues[isolanguepos]); + impvalues[isolanguepos] = LeadImportUtils.checkISOLanguage(impvalues[isolanguepos]); + } + try//import data { var dupCheck = LeadImportUtils.importData(DataFields, DataTypes, FieldDef, impvalues, importdefid, AttrObject, source, user, currDate);