Skip to content
Snippets Groups Projects
Commit a5437d44 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

Do not use db.getColumns("LEADTEMP"); as the order of the columns is not guaranteed

parent 394c489a
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ import("Keyword_lib");
import("Sql_lib");
import("system.db");
import("system.vars");
import("Leadimport_lib");
var assignmentRowId = vars.get("$field.LEADIMPORTID");
var importDate = vars.get("$field.LEADIMPORT_DATE");
......@@ -33,7 +33,7 @@ data = util.decodeBase64String(data);
var table = text.parseCSV(data.replace(/(^\s+)|(\s+$)/g,""), recordSep, fieldSep, fieldLimit.charAt(0));
var insertTable = "LEADTEMP";
var insertCols = db.getColumns("LEADTEMP");
var insertCols = LeadImportUtils.leadTempColumns();
var insertTypes = db.getColumnTypes(insertTable, insertCols);
var insertVals = [];
......@@ -55,6 +55,7 @@ for (i = 0; i < table.length; i++)//and load new
insertVals.push(importDate, util.getNewUUID(), importName, i.toString(), assignmentRowId);//push other necessary data for the insert
toInsert.push([insertTable, insertCols, insertTypes, insertVals]);
}
db.inserts(toInsert);
question.showMessage("Daten wurden geladen! Zeilen: " + eMath.subInt(table.length, 1));
......
......@@ -13,6 +13,62 @@ import("system.util");
import("Sql_lib");
import("system.db");
/**
* functions for the lead import
* Do not create an instance of this!
*
* @class
* @static
*/
function LeadImportUtils(){}
/**
* Returns the columns of the LEADTEMP table.
* Do not use db.getColumns("LEADTEMP"); as the order of the columns is not guaranteed!
*
* @return {String[]} all columns
*/
LeadImportUtils.leadTempColumns = function()
{
return [
"COLUMN01",
"COLUMN02",
"COLUMN03",
"COLUMN04",
"COLUMN05",
"COLUMN06",
"COLUMN07",
"COLUMN08",
"COLUMN09",
"COLUMN10",
"COLUMN11",
"COLUMN12",
"COLUMN13",
"COLUMN14",
"COLUMN15",
"COLUMN16",
"COLUMN17",
"COLUMN18",
"COLUMN19",
"COLUMN20",
"COLUMN21",
"COLUMN22",
"COLUMN23",
"COLUMN24",
"COLUMN25",
"COLUMN26",
"COLUMN27",
"COLUMN28",
"COLUMN29",
"COLUMN30",
"IMPORT_DATE",
"LEADTEMPID",
"NAME",
"POSITION",
"ROW_ID"
];
}
/*
* Load the data
*
......@@ -993,28 +1049,22 @@ function scanLeadDups(pAllContactData){
*/
function CheckDup( pLeadValues)
{
//var condition = " where ";
var condition = SqlCondition.begin();
// search whether the organisation already exists
var query = newSelect("ORGANISATIONID, CONTACTID")
.from("ORGANISATION")
.join("CONTACT", "ORGANISATIONID = CONTACT.ORGANISATION_ID")
.join("ADDRESS", "ADDRESSID = ADDRESS_ID");
var fields;
fields = ["ORGANISATION.NAME", "ADDRESS.COUNTRY", "ADDRESS.ADDRESS", "ADDRESS.CITY", "ADDRESS.ZIP", "ADDRESS.COUNTRY"];
condition.and("PERSON_ID is null");
query.and("PERSON_ID is null");
for (var i = 0; i < fields.length; i++)
{
condition.andPrepare(fields[i], pLeadValues[ fields[i].split(".")[1] ].replace(new RegExp("'", "g"),"''"));
condition.and(fields[i] + " is not null");
query.and(fields[i], pLeadValues[ fields[i].split(".")[1] ].replace(new RegExp("'", "g"),"''"));
query.and(fields[i] + " is not null");
}
// search whether the organisation already exists
var ids = db.array(db.ROW, SqlBuilder.begin()
.select("ORGANISATIONID, CONTACTID")
.from("ORGANISATION")
.join("CONTACT", "ORGANISATIONID = CONTACT.ORGANISATION_ID")
.join("ADDRESS", "ADDRESSID = ADDRESS_ID")
.where(condition)
.build());
return ids;
return query.array();
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment