diff --git a/entity/Address_entity/Address_entity.aod b/entity/Address_entity/Address_entity.aod
index 411c2c787d5f7bba8e475322a0ffb04bb190e5ea..c5c6b35e0072eb8f76b9bd0bb5a09fdbc95f69dd 100644
--- a/entity/Address_entity/Address_entity.aod
+++ b/entity/Address_entity/Address_entity.aod
@@ -488,6 +488,10 @@
       <name>ContactIds_param</name>
       <expose v="true" />
     </entityParameter>
+    <entityParameter>
+      <name>ReplaceStandardAddress_param</name>
+      <expose v="true" />
+    </entityParameter>
   </entityFields>
   <recordContainers>
     <dbRecordContainer>
diff --git a/entity/Address_entity/recordcontainers/db/onDBInsert.js b/entity/Address_entity/recordcontainers/db/onDBInsert.js
index 2560a9b9b7b6f1d76f9c508d177b1c284500e9f1..199ad53da66642101b7ce8a6a5bfe6397f72fb4d 100644
--- a/entity/Address_entity/recordcontainers/db/onDBInsert.js
+++ b/entity/Address_entity/recordcontainers/db/onDBInsert.js
@@ -1,3 +1,4 @@
+import("system.logging");
 import("KeywordRegistry_basic");
 import("DataPrivacy_lib");
 import("system.vars");
@@ -22,6 +23,6 @@ else if (typeParam === "organisation")
     scopeType = "Organisation"
 
 new StandardObject("Address", vars.get("$local.uid"), scopeType, rowdata["ADDRESS.CONTACT_ID"])
-    .onObjectInsert()
+    .onObjectInsert(vars.exists("$param.ReplaceStandardAddress_param") ? vars.get("$param.ReplaceStandardAddress_param") : undefined)
 
-DataPrivacyUtils.notifyNeedDataPrivacyUpdate(rowdata["ADDRESS.CONTACT_ID"], vars.get("$param.ShowDsgvoMessage_param"));
\ No newline at end of file
+DataPrivacyUtils.notifyNeedDataPrivacyUpdate(rowdata["ADDRESS.CONTACT_ID"], vars.get("$param.ShowDsgvoMessage_param"));
diff --git a/entity/Analyses_entity/entityfields/new_tasks/valueProcess.js b/entity/Analyses_entity/entityfields/new_tasks/valueProcess.js
index 8aa5325599c2c82547daca6456d57aebe5269313..510afae5b2c0dfeb0451be8d4d176fc18bb6258c 100644
--- a/entity/Analyses_entity/entityfields/new_tasks/valueProcess.js
+++ b/entity/Analyses_entity/entityfields/new_tasks/valueProcess.js
@@ -1,9 +1,13 @@
 import("Employee_lib");
 import("system.db");
 import("system.result");
-
-var opentask = db.cell("select count(TASKID) "
-             + " from TASK "
-             + " where STATUS = 'NEW' and EDITOR_CONTACT_ID = '" + EmployeeUtils.getCurrentContactId() + "'");                             
-                                  
-result.string(opentask);
\ No newline at end of file
+import("Sql_lib");
+import("KeywordRegistry_basic");
+                     
+var opentask = newSelect("count(TASKID)")
+    .from("TASK")
+    .where("TASK.STATUS", $KeywordRegistry.taskStatus$new())
+    .and("TASK.EDITOR_CONTACT_ID", EmployeeUtils.getCurrentContactId())
+    .cell();
+    
+result.string(opentask || 0);
\ No newline at end of file
diff --git a/entity/Analyses_entity/entityfields/opennewtasks/onActionProcess.js b/entity/Analyses_entity/entityfields/opennewtasks/onActionProcess.js
index 696d1e7e7cf42aea7dd618f8c87b3cca400ce57b..696815d5aed5b5a1394a46b3f2d46c29fff8a024 100644
--- a/entity/Analyses_entity/entityfields/opennewtasks/onActionProcess.js
+++ b/entity/Analyses_entity/entityfields/opennewtasks/onActionProcess.js
@@ -1,9 +1,12 @@
+import("KeywordRegistry_basic");
+import("Sql_lib");
 import("Employee_lib");
-import("system.db");
 import("system.neon");
 
-var taskIds = db.table("select TASKID  "
-             + " from TASK "
-             + " where STATUS = 'NEW' and EDITOR_CONTACT_ID = '" + EmployeeUtils.getCurrentContactId() + "'", "Data_alias");
-
+var taskIds = newSelect("TASKID")
+    .from("TASK")
+    .where("TASK.STATUS", $KeywordRegistry.taskStatus$new())
+    .and("TASK.EDITOR_CONTACT_ID", EmployeeUtils.getCurrentContactId())
+    .arrayColumn();
+    
 neon.openContext("Task", "TaskFilter_view", taskIds, neon.OPERATINGSTATE_SEARCH, null);
\ No newline at end of file
diff --git a/entity/Analyses_entity/entityfields/turnover_forecast/valueProcess.js b/entity/Analyses_entity/entityfields/turnover_forecast/valueProcess.js
index 72d7b1588dc53ebc626e3d3fe4691d195f95e69d..1ac6f93dde00d8dc071d67fe38793c19a81e11ec 100644
--- a/entity/Analyses_entity/entityfields/turnover_forecast/valueProcess.js
+++ b/entity/Analyses_entity/entityfields/turnover_forecast/valueProcess.js
@@ -8,7 +8,7 @@ import("system.SQLTYPES")
 
 var forecast = newSelect("sum(VOLUME)")
                 .from("FORECAST")
-                .where("FORECAST.DATE_START", datetime.toDate(vars.get("$sys.date"), "yyyy"), "year(#) = ?", SQLTYPES.INTEGER)
+                .where("FORECAST.DATE_START", DateUtils.getCurrentYear(), SqlBuilder.YEAR_EQUALS(), SQLTYPES.INTEGER)
                 .cell();
                                   
-result.string(forecast);
\ No newline at end of file
+result.string(forecast || 0);
\ No newline at end of file
diff --git a/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js b/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js
index a7b6c13eace48fe528b78dcaf529cb043068fc0c..fbe2e30a6b835af9cd32c48ab79963dae88229c6 100644
--- a/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Attribute_entity/recordcontainers/jdito/contentProcess.js
@@ -122,11 +122,6 @@ if (fetchUsages) //this query is only necessary in Attribute, not in AttributeRe
     }
 }
 
-
-var sqlSelect = "select AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME, ATTRIBUTE_ACTIVE, DROPDOWNDEFINITION, DROPDOWNFILTER, SORTING, ATTRIBUTE_TYPE, " 
-    + KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.attributeType(), "ATTRIBUTE_TYPE") //3
-    + ", '', '', '' from AB_ATTRIBUTE"; 
-
 var attributes = newSelect("AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME, ATTRIBUTE_ACTIVE, DROPDOWNDEFINITION, DROPDOWNFILTER, SORTING, ATTRIBUTE_TYPE, " 
                             + KeywordUtils.getResolvedTitleSqlPart($KeywordRegistry.attributeType(), "ATTRIBUTE_TYPE") //3
                             + ", '', '', ''")
@@ -136,7 +131,7 @@ var attributes = newSelect("AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME,
                     .table();
 
 //TODO: attribute name caching like keywords
-var allNames = db.table("select AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME from AB_ATTRIBUTE");
+var allNames = newSelect("AB_ATTRIBUTEID, ATTRIBUTE_PARENT_ID, ATTRIBUTE_NAME").from("AB_ATTRIBUTE").table();
 var attrNameData = {};
 for (let i = 0, l = allNames.length; i < l; i++)
 {
diff --git a/entity/BulkMailAddRecipients_entity/entityfields/bulkmail_id/displayValueProcess.js b/entity/BulkMailAddRecipients_entity/entityfields/bulkmail_id/displayValueProcess.js
index 908c3e0ae7eaa406fd40e4fe5aeaf0b03822df9d..b3e0f9ffb752940e768855eb978b668af263fec8 100644
--- a/entity/BulkMailAddRecipients_entity/entityfields/bulkmail_id/displayValueProcess.js
+++ b/entity/BulkMailAddRecipients_entity/entityfields/bulkmail_id/displayValueProcess.js
@@ -1,13 +1,11 @@
 import("system.vars");
 import("Sql_lib");
-import("system.db");
 import("system.result");
 
 if (vars.get("$this.value"))
     result.string(newSelect("NAME")
                     .from("BULKMAIL")
                     .where("BULKMAIL.BULKMAILID", "$this.value")
-                    .buildSql("select NAME from BULKMAIL")
                     .cell());
 else
     result.string("");
\ No newline at end of file
diff --git a/entity/BulkMail_entity/BulkMail_entity.aod b/entity/BulkMail_entity/BulkMail_entity.aod
index a967c20f616cda692961673640b24527c3eefe9c..b4956b36573f48cecee456967cba0759a03538e5 100644
--- a/entity/BulkMail_entity/BulkMail_entity.aod
+++ b/entity/BulkMail_entity/BulkMail_entity.aod
@@ -113,6 +113,7 @@
     </entityConsumer>
     <entityField>
       <name>bindata</name>
+      <title>Custom template</title>
       <contentType>FILE</contentType>
       <valueProcess>%aditoprj%/entity/BulkMail_entity/entityfields/bindata/valueProcess.js</valueProcess>
       <onValueChange>%aditoprj%/entity/BulkMail_entity/entityfields/bindata/onValueChange.js</onValueChange>
diff --git a/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/conditionProcess.js b/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/conditionProcess.js
index a9971811a54d5b707ba3b11b10f93682ff0ca93a..b3b5019620eeb8f41f7fdf43f8769f9c275b2888 100644
--- a/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/conditionProcess.js
+++ b/entity/CampaignParticipant_entity/recordcontainers/participantsdbrecordcontainer/conditionProcess.js
@@ -1,18 +1,9 @@
+import("Sql_lib");
 import("system.result");
 import("system.vars");
 
-var resultValue;
-if(vars.get("$param.CampaignId_param") != null && vars.get("$param.CampaignId_param") != "")
-{
-    resultValue = "CAMPAIGN_ID = '" + vars.get("$param.CampaignId_param") + "'";
-    
-    if(vars.get("$param.CampaignStepId_param") != null && vars.get("$param.CampaignStepId_param") != "")
-        resultValue += " AND CAMPAIGNSTEP_ID = '" + vars.get("$param.CampaignStepId_param") + "'";
-    
-    result.string(resultValue);
-}
-else if(vars.get("$param.CampaignStepId_param") != null && vars.get("$param.CampaignStepId_param") != "")
-    {
-        resultValue = "CAMPAIGNSTEP_ID = '" + vars.get("$param.CampaignStepId_param") + "'";
-        result.string(resultValue);
-    }
\ No newline at end of file
+var condition = newWhere()
+    .andIfSet("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", "$param.CampaignId_param")
+    .andIfSet("CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID", "$param.CampaignStepId_param");
+
+result.string(condition.toString());
diff --git a/entity/CampaignStep_entity/entityfields/sorting/valueProcess.js b/entity/CampaignStep_entity/entityfields/sorting/valueProcess.js
index 6c154f155aefa6c6f90ab008b34aa963657770b7..14299877ed48151d1547cb1f8be4df680bc61a08 100644
--- a/entity/CampaignStep_entity/entityfields/sorting/valueProcess.js
+++ b/entity/CampaignStep_entity/entityfields/sorting/valueProcess.js
@@ -1,4 +1,4 @@
-import("system.db");
+import("Sql_lib");
 import("system.neon");
 import("system.vars");
 import("system.util");
@@ -7,8 +7,9 @@ import("system.result");
 if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
 {
     var campaignId = vars.get("$field.CAMPAIGN_ID");
-    var latestSortingQuery = "select COUNT(CAMPAIGNSTEPID) from CAMPAIGNSTEP " + 
-        "where CAMPAIGN_ID = '" + campaignId + "'";
-    var stepCount = db.cell(latestSortingQuery);
+    var stepCount = newSelect("count(CAMPAIGNSTEPID)")
+        .from("CAMPAINGSTEP")
+        .where("CAMPAIGNSTEP.CAMPAIGN_ID", campaignId)
+        .cell();
     result.string(parseInt(stepCount) + 1);
 }
\ No newline at end of file
diff --git a/entity/Campaign_entity/recordcontainers/db/conditionProcess.js b/entity/Campaign_entity/recordcontainers/db/conditionProcess.js
index 48e7a6cbbddcac3d8fe7def09dcc51fc47240d78..5f3455bc5b51c66cf6a7cd0ed14899bc09356fd9 100644
--- a/entity/Campaign_entity/recordcontainers/db/conditionProcess.js
+++ b/entity/Campaign_entity/recordcontainers/db/conditionProcess.js
@@ -7,5 +7,5 @@ import("system.vars");
 if(vars.get("$param.ShowOnlyCurrentUsersCampaigns_param") == 'true')
 {
     //TODO: use a preparedCondition (.build instead of .translate) when available #1030812 #1034026
-    result.string("CAMPAIGN.EMPLOYEE_CONTACT_ID = '" + EmployeeUtils.getCurrentContactId() + "'");
+    result.string(newWhere("CAMPAIGN.EMPLOYEE_CONTACT_ID", EmployeeUtils.getCurrentContactId()).toString());
 }
\ No newline at end of file
diff --git a/entity/Contract_entity/conditionProcess.js b/entity/Contract_entity/conditionProcess.js
index a1bd70f1174309288cfb62611a5c91d0695572d8..b40df37b5c21d8eb1dbf1f28efe0e857fc33f8a6 100644
--- a/entity/Contract_entity/conditionProcess.js
+++ b/entity/Contract_entity/conditionProcess.js
@@ -1,7 +1,9 @@
+import("Sql_lib");
 import("system.result");
 import("system.vars");
 
-if(vars.exists("$param.ContactId_param") && vars.get("$param.ContactId_param") != null && vars.get("$param.ContactId_param") != "")
-    result.string("CONTRACT.CONTACT_ID = ('" + vars.getString("$param.ContactId_param") + "')");  
-else
-    result.string("1 = 1");  
\ No newline at end of file
+var condition = newWhere();
+if (vars.exists("$param.ContactId_param"))
+    condition.andIfSet("CONTRACT.CONTACT_ID", "$param.ContactId_param");
+
+result.string(condition.toString("1=1"));
\ No newline at end of file
diff --git a/entity/DuplicateScannerIndexConfig_entity/recordcontainers/recordcontainer/conditionProcess.js b/entity/DuplicateScannerIndexConfig_entity/recordcontainers/recordcontainer/conditionProcess.js
index 09f2397fdf9818efae79ef28201915ffc52639c3..43719039395d018a0dda9921ed8a1090e4e38c88 100644
--- a/entity/DuplicateScannerIndexConfig_entity/recordcontainers/recordcontainer/conditionProcess.js
+++ b/entity/DuplicateScannerIndexConfig_entity/recordcontainers/recordcontainer/conditionProcess.js
@@ -1,7 +1,5 @@
 import("system.vars");
 import("system.result");
 
-if(vars.get("$param.DuplicateScannerId_param"))
-{
-    result.string("DUPLICATESCANNER_ID = '" + vars.getString("$param.DuplicateScannerId_param") + "'");
-}
\ No newline at end of file
+if (vars.get("$param.DuplicateScannerId_param"))
+    result.string(newWhere("DUPLICATESCANNERINDEXCONFIG.DUPLICATESCANNER_ID", "$param.DuplicateScannerId_param").toString());
\ No newline at end of file
diff --git a/entity/DuplicateScannerPrefilterConfig_entity/recordcontainers/dbrecordcontainer/conditionProcess.js b/entity/DuplicateScannerPrefilterConfig_entity/recordcontainers/dbrecordcontainer/conditionProcess.js
index 09f2397fdf9818efae79ef28201915ffc52639c3..84dac3bb3370942bb035ed8293bd2d6c9ee9a8d8 100644
--- a/entity/DuplicateScannerPrefilterConfig_entity/recordcontainers/dbrecordcontainer/conditionProcess.js
+++ b/entity/DuplicateScannerPrefilterConfig_entity/recordcontainers/dbrecordcontainer/conditionProcess.js
@@ -1,7 +1,5 @@
 import("system.vars");
 import("system.result");
 
-if(vars.get("$param.DuplicateScannerId_param"))
-{
-    result.string("DUPLICATESCANNER_ID = '" + vars.getString("$param.DuplicateScannerId_param") + "'");
-}
\ No newline at end of file
+if (vars.get("$param.DuplicateScannerId_param"))
+    result.string(newWhere("DUPLICATESCANNERPREFILTERCONFIG.DUPLICATESCANNER_ID", "$param.DuplicateScannerId_param").toString());
\ No newline at end of file
diff --git a/entity/DuplicateScannerResultFieldConfig_entity/recordcontainers/recordcontainer/conditionProcess.js b/entity/DuplicateScannerResultFieldConfig_entity/recordcontainers/recordcontainer/conditionProcess.js
index 09f2397fdf9818efae79ef28201915ffc52639c3..b9bff609c91222abb6c3b0292492600907585487 100644
--- a/entity/DuplicateScannerResultFieldConfig_entity/recordcontainers/recordcontainer/conditionProcess.js
+++ b/entity/DuplicateScannerResultFieldConfig_entity/recordcontainers/recordcontainer/conditionProcess.js
@@ -1,7 +1,5 @@
 import("system.vars");
 import("system.result");
 
-if(vars.get("$param.DuplicateScannerId_param"))
-{
-    result.string("DUPLICATESCANNER_ID = '" + vars.getString("$param.DuplicateScannerId_param") + "'");
-}
\ No newline at end of file
+if (vars.get("$param.DuplicateScannerId_param"))
+    result.string(newWhere("DUPLICATESCANNERRESULTFIELDCONFIG.DUPLICATESCANNER_ID", "$param.DuplicateScannerId_param").toString());
\ No newline at end of file
diff --git a/entity/Email_entity/Email_entity.aod b/entity/Email_entity/Email_entity.aod
index 1c0cd341fd59b80470893b5820243eb195a50997..78e2c87c878736774a82461cb78f50f04c1412fb 100644
--- a/entity/Email_entity/Email_entity.aod
+++ b/entity/Email_entity/Email_entity.aod
@@ -65,6 +65,7 @@
     </entityParameter>
     <entityField>
       <name>bindata</name>
+      <title>Custom template</title>
       <contentType>FILE</contentType>
     </entityField>
     <entityActionField>
diff --git a/entity/KeywordAttributeRelation_entity/entityfields/valueproxy/valueProcess.js b/entity/KeywordAttributeRelation_entity/entityfields/valueproxy/valueProcess.js
index 5abab4366e646022bb99bfcd378f9e2793feeaa2..586823ef8a196336119ecf37dc8aada6619f6fb0 100644
--- a/entity/KeywordAttributeRelation_entity/entityfields/valueproxy/valueProcess.js
+++ b/entity/KeywordAttributeRelation_entity/entityfields/valueproxy/valueProcess.js
@@ -1,25 +1,28 @@
 import("system.result");
 import("system.vars");
 
-var type = vars.get("$field.attributeType");
-var value;
-switch (type)
+var value = vars.get("$this.value");
+if (!value)
 {
-    case "BOOL_VALUE":
-        value = vars.get("$field.BOOL_VALUE");
-        break;
-    case "NUMBER_VALUE":
-        value = vars.get("$field.NUMBER_VALUE");
-        break;
-    case "CHAR_VALUE":
-        value = vars.get("$field.CHAR_VALUE");
-        break;    
-    case "LONG_CHAR_VALUE":
-        value = vars.get("$field.LONG_CHAR_VALUE");
-        break;
-    default: 
-        value = null;
-        break;
+    var type = vars.get("$field.attributeType");
+    switch (type)
+    {
+        case "BOOL_VALUE":
+            value = vars.get("$field.BOOL_VALUE");
+            break;
+        case "NUMBER_VALUE":
+            value = vars.get("$field.NUMBER_VALUE");
+            break;
+        case "CHAR_VALUE":
+            value = vars.get("$field.CHAR_VALUE");
+            break;    
+        case "LONG_CHAR_VALUE":
+            value = vars.get("$field.LONG_CHAR_VALUE");
+            break;
+        default: 
+            value = null;
+            break;
+    }
 }
 
 result.string(value);
\ No newline at end of file
diff --git a/entity/Letter_entity/Letter_entity.aod b/entity/Letter_entity/Letter_entity.aod
index d4a202aae2cb46f690bbdb8b56f857d56c92005d..97fe0b3fe0f8b3941814784df8d37edfe24a932c 100644
--- a/entity/Letter_entity/Letter_entity.aod
+++ b/entity/Letter_entity/Letter_entity.aod
@@ -38,6 +38,7 @@
     </entityParameter>
     <entityField>
       <name>bindata</name>
+      <title>Custom template</title>
       <contentType>FILE</contentType>
     </entityField>
     <entityActionField>
diff --git a/entity/Order_entity/entityfields/contact_id/onValueChange.js b/entity/Order_entity/entityfields/contact_id/onValueChange.js
index a65930ffa61d383b2d12068e75e6fae55585bc50..d0c5b9a5c46eebb0b70f5da897cd3ddd571b93ab 100644
--- a/entity/Order_entity/entityfields/contact_id/onValueChange.js
+++ b/entity/Order_entity/entityfields/contact_id/onValueChange.js
@@ -1,15 +1,17 @@
+import("Sql_lib");
 import("system.neon");
 import("system.vars");
-import("system.db");
 import("Util_lib");
 import("Entity_lib");
 
 var contactid = vars.get("local.value");
-if(contactid != "")
-{
-    var relData = db.array(db.ROW, "select ISOLANGUAGE from CONTACT where CONTACTID = '" + contactid + "'");
-    
-    if(relData[0] != "")   
-        vars.set("$field.ISOLANGUAGE", relData[0]);
-}
+
+var relData = newSelect("ISOLANGUAGE")
+    .from("CONTACT")
+    .whereIfSet("CONTACT.CONTACTID", contactid)
+    .cell(true);
+
+if(relData)   
+    vars.set("$field.ISOLANGUAGE", relData[0]);
+
 neon.setFieldValue("$field.OBJECT_ROWID", null)
\ No newline at end of file
diff --git a/entity/Organisation_entity/entityfields/countactivity/valueProcess.js b/entity/Organisation_entity/entityfields/countactivity/valueProcess.js
index d3606bbab63de69eb4ed3b2e3748368af23f1d30..08f56eefb94c18f0a059f51e81c63e9bbafaaea2 100644
--- a/entity/Organisation_entity/entityfields/countactivity/valueProcess.js
+++ b/entity/Organisation_entity/entityfields/countactivity/valueProcess.js
@@ -1,7 +1,13 @@
+import("Context_lib");
+import("Sql_lib");
 import("system.result");
 import("system.vars");
-import("system.db");
-var amount = db.cell("select count(ACTIVITYID) from ACTIVITY join ACTIVITYLINK on ACTIVITYLINK.ACTIVITY_ID = ACTIVITY.ACTIVITYID \n\
-                      where ACTIVITYLINK.OBJECT_ROWID = '" + vars.get("$field.CONTACTID") + "' and ACTIVITYLINK.OBJECT_TYPE = 'Organisation'");
 
+var amount = newSelect("count(ACTIVITYID)")
+    .from("ACTIVITY")
+    .join("ACTIVITYLINK", "ACTIVITYLINK.ACTIVITY_ID = ACTIVITY.ACTIVITYID")
+    .where("ACTIVITYLINK.OBJECT_ROWID", "$field.CONTACTID")
+    .and("ACTIVITYLINK.OBJECT_TYPE", ContextUtils.getCurrentContextId())
+    .cell(null, "0");
+    
 result.string(amount);
\ No newline at end of file
diff --git a/entity/Organisation_entity/entityfields/turnovercurrentyear/valueProcess.js b/entity/Organisation_entity/entityfields/turnovercurrentyear/valueProcess.js
index 1f8ee1ceff032c2caab8194406bdc69ad585f039..f1418b164048dd71adae85c9dfb29e21c80a2cbf 100644
--- a/entity/Organisation_entity/entityfields/turnovercurrentyear/valueProcess.js
+++ b/entity/Organisation_entity/entityfields/turnovercurrentyear/valueProcess.js
@@ -1,3 +1,6 @@
+import("Date_lib");
+import("system.SQLTYPES");
+import("Sql_lib");
 import("system.translate");
 import("Util_lib");
 import("system.datetime");
@@ -6,12 +9,10 @@ import("system.db");
 import("system.result");
 import("system.date");
 
-var currentYear = datetime.toDate(vars.get("$sys.date"), "yyyy");
+var salesCurrentYear = newSelect("sum(NET)")
+    .from("SALESORDER")
+    .where("SALESORDER.SALESORDERDATE", DateUtils.getCurrentYear(), SqlBuilder.YEAR_EQUALS(), SQLTYPES.INTEGER)
+    .and("SALESORDER.CONTACT_ID", "$field.CONTACTID")
+    .cell();
 
-var salesCurrentYear = db.cell("select SUM(NET) from salesorder where SALESORDERDATE >= '" + currentYear + "-01-01 00:00:00.000' \n\
-                                                                and CONTACT_ID = '" + vars.get("$field.CONTACTID") + "'");
-
-if(salesCurrentYear == "")
-    salesCurrentYear = 0;
-
-result.string(salesCurrentYear);
\ No newline at end of file
+result.string(salesCurrentYear || 0);
\ No newline at end of file
diff --git a/entity/Organisation_entity/entityfields/turnoverlastyear/valueProcess.js b/entity/Organisation_entity/entityfields/turnoverlastyear/valueProcess.js
index f89ea7a28deec7a4b5f43991fdf9938fdade25c1..181f0fdcedb69df5ac62f8b1da2e60f66259c09d 100644
--- a/entity/Organisation_entity/entityfields/turnoverlastyear/valueProcess.js
+++ b/entity/Organisation_entity/entityfields/turnoverlastyear/valueProcess.js
@@ -1,16 +1,16 @@
+import("system.SQLTYPES");
+import("Date_lib");
+import("Sql_lib");
 import("system.datetime");
 import("system.vars");
 import("system.db");
 import("system.result");
 import("system.date");
 
-var lastYear = parseInt(datetime.toDate(vars.get("$sys.date"), "yyyy")) - 1;
+var salesLastYear = newSelect("sum(NET)")
+    .from("SALESORDER")
+    .where("SALESORDER.SALESORDERDATE", DateUtils.getCurrentYear() - 1, SqlBuilder.YEAR_EQUALS(), SQLTYPES.INTEGER)
+    .and("SALESORDER.CONTACT_ID", "$field.CONTACTID")
+    .cell();
 
-var salesLastYear = db.cell("select SUM(NET) from salesorder where SALESORDERDATE < '" + (lastYear+1) + "-01-01 00:00:00.000' \n\
-                                                             and SALESORDERDATE >= '" + lastYear + "-01-01 00:00:00.000'  \n\
-                                                             and CONTACT_ID = '" + vars.get("$field.CONTACTID") + "'");
-
-if(salesLastYear == "")
-    salesLastYear = 0;
-
-result.string(salesLastYear);
\ No newline at end of file
+result.string(salesLastYear || 0);
\ No newline at end of file
diff --git a/entity/Person_entity/Person_entity.aod b/entity/Person_entity/Person_entity.aod
index 8ddf9367f4a5c9b382b7e53be31c39a4858643b0..5fb1612abc79b2a23c603c3092d5e09bf69592e4 100644
--- a/entity/Person_entity/Person_entity.aod
+++ b/entity/Person_entity/Person_entity.aod
@@ -176,6 +176,10 @@ This field only calculates the Orgid from the ORGANISATION_CONTACTID to save it
           <name>ShowDsgvoMessage_param</name>
           <valueProcess>%aditoprj%/entity/Person_entity/entityfields/persaddresses/children/showdsgvomessage_param/valueProcess.js</valueProcess>
         </entityParameter>
+        <entityParameter>
+          <name>ReplaceStandardAddress_param</name>
+          <valueProcess>%aditoprj%/entity/Person_entity/entityfields/persaddresses/children/replacestandardaddress_param/valueProcess.js</valueProcess>
+        </entityParameter>
       </children>
     </entityConsumer>
     <entityConsumer>
diff --git a/entity/Person_entity/entityfields/persaddresses/children/replacestandardaddress_param/valueProcess.js b/entity/Person_entity/entityfields/persaddresses/children/replacestandardaddress_param/valueProcess.js
new file mode 100644
index 0000000000000000000000000000000000000000..41522d06159dc6b95252b269220319760dcd36fa
--- /dev/null
+++ b/entity/Person_entity/entityfields/persaddresses/children/replacestandardaddress_param/valueProcess.js
@@ -0,0 +1,8 @@
+import("system.neon");
+import("system.vars");
+import("system.result");
+
+//this parameter allows the address entity to set a itself as the standard address
+//if the current standard address is the given id
+if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW)
+    result.string(vars.get("$field.ADDRESS_ID"));
\ No newline at end of file
diff --git a/entity/Person_entity/recordcontainers/db/onDBInsert.js b/entity/Person_entity/recordcontainers/db/onDBInsert.js
index eb22217f25b73bf8443d32cae8969d7ec4aea56a..5f069680c3cd50ac7a7b062d6a9c55a22a176dcc 100644
--- a/entity/Person_entity/recordcontainers/db/onDBInsert.js
+++ b/entity/Person_entity/recordcontainers/db/onDBInsert.js
@@ -72,4 +72,6 @@ notification.addNotificationWith(notificationConfig);
 
 //notification.addNotification(util.getNewUUID(), null, null, null, "_____SYSTEM_NOTIFICATION_MESSAGE", notification.PRIO_NORMAL, 1, notification.STATE_UNSEEN, [EmployeeUtils.getCurrentUserId()], "message", "description");
 
-}
\ No newline at end of file
+}
+
+var persAdress
\ No newline at end of file
diff --git a/entity/Prod2prod_entity/entityfields/products/children/excludedproducts_param/valueProcess.js b/entity/Prod2prod_entity/entityfields/products/children/excludedproducts_param/valueProcess.js
index 61d089f5dbb0ce3bdb487cd54971966dcb4db26d..bbca20492052f0f34e6997a999c968dca4ab821e 100644
--- a/entity/Prod2prod_entity/entityfields/products/children/excludedproducts_param/valueProcess.js
+++ b/entity/Prod2prod_entity/entityfields/products/children/excludedproducts_param/valueProcess.js
@@ -1,3 +1,4 @@
+import("Sql_lib");
 import("system.neon");
 import("system.db");
 import("system.vars");
@@ -34,8 +35,10 @@ result.object(excludeIDs);
 function _getParentID(pID, pIDs)
 {
     //Ermitteln welche Produkte ausgeschlossen werden müssen.
-    cond = typeof(pID) == "object" ? "in  ('" + pID.join("', '") +"')" : " =  '" + pID + "' "   
-    var parents = db.array(db.COLUMN, "select DEST_ID from PROD2PROD where SOURCE_ID " + cond);
+    var parents = newSelect("DEST_ID")
+        .from("PROD2PROD")
+        .whereIfSet("PROD2PROD.SOURCE_ID", pID, typeof(pID) == "string" ? null : SqlBuilder.IN())
+        .arrayColumn(true);
     for ( var i = 0; i < parents.length; i++)
     {    
         pIDs.push(parents[i]);
@@ -46,8 +49,10 @@ function _getParentID(pID, pIDs)
 function _getChildrenID(pID, pIDs)
 {
     //Ermitteln welche Produkte ausgeschlossen werden müssen.
-    cond = typeof(pID) == "object" ? "in  ('" + pID.join("', '") +"')" : " =  '" + pID + "' "
-    var children = db.array(db.COLUMN, "select SOURCE_ID from PROD2PROD where DEST_ID " + cond);
+    var children = newSelect("SOURCE_ID")
+        .from("PROD2PROD")
+        .whereIfSet("PROD2PROD.DEST_ID", pID, typeof(pID) == "string" ? null : SqlBuilder.IN())
+        .arrayColumn(true);
     for ( var i = 0; i < children.length; i++)
     {    
         pIDs.push(children[i]);
diff --git a/entity/Prod2prod_entity/recordcontainers/jdito/contentProcess.js b/entity/Prod2prod_entity/recordcontainers/jdito/contentProcess.js
index 468aab3158406abdeb1858ec6a58d34f48810536..aafbf045045fcfc93eef8fb7be622c9036827ce9 100644
--- a/entity/Prod2prod_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/Prod2prod_entity/recordcontainers/jdito/contentProcess.js
@@ -147,9 +147,11 @@ else
     if(prodid != "")
     {
         // First 3 columns are crucial, the rest is optional.
-        var data = db.table("select PROD2PRODID, SOURCE_ID, DEST_ID, QUANTITY, PRODUCTCODE, PRODUCTID, PROD2PRODID, OPTIONAL, TAKEPRICE, PRODUCTNAME "
-                    + "from PROD2PROD join PRODUCT on PROD2PROD.SOURCE_ID = PRODUCTID "
-                    + "order by PRODUCTCODE");
+        var data = newSelect("PROD2PRODID, SOURCE_ID, DEST_ID, QUANTITY, PRODUCTCODE, PRODUCTID, PROD2PRODID, OPTIONAL, TAKEPRICE, PRODUCTNAME")
+            .from("PROD2PROD")
+            .join("PRODUCT", "PROD2PROD.SOURCE_ID = PRODUCTID")
+            .orderBy("PRODUCTCODE")
+            .table();
 
         var prod2prodIdMapping = buildProd2ProdIDMapping(data);
         var childrenMapping = buildChildrenMapping(data);
diff --git a/entity/Product_entity/entityfields/productcode/onValidation.js b/entity/Product_entity/entityfields/productcode/onValidation.js
index 81b90e9b479276bb7057bfd12d6890d50fdde20b..2e11d9ff11664a2b07fa28e90c55b2d2d14fd149 100644
--- a/entity/Product_entity/entityfields/productcode/onValidation.js
+++ b/entity/Product_entity/entityfields/productcode/onValidation.js
@@ -1,15 +1,13 @@
+import("Sql_lib");
 import("system.translate");
 import("system.result");
-import("system.vars");
-import("system.db");
-import("Util_lib");
-import("Entity_lib");
 
-var codeCount, productCode;
-
-productCode = vars.get("local.value");
-codeCount = db.cell("select count(PRODUCTCODE) from PRODUCT where PRODUCTCODE = '" + productCode + "'"
-                       + " and PRODUCTID <> '" + vars.get("$field.PRODUCTID") + "'");
+var codeCount = newSelect("count(PRODUCTCODE)")
+    .from("PRODUCT")
+    .where("PRODUCT.PRODUCTCODE", "$local.value")
+    .and("PRODUCT.PRODUCTID", "$field.PRODUCTID", "# != ?")
+    .cell();
+    
 if(codeCount > 0)
 {
     result.string(translate.text("The product number already exists!"));
diff --git a/entity/Productprice_entity/entityfields/attributes/children/filteredattributes_param/valueProcess.js b/entity/Productprice_entity/entityfields/attributes/children/filteredattributes_param/valueProcess.js
index 8e1a22ffe0d6b4fbed6611161f1fa121edbdc428..69acbaabdeb26f9d1b05f34290073efec5aa8d76 100644
--- a/entity/Productprice_entity/entityfields/attributes/children/filteredattributes_param/valueProcess.js
+++ b/entity/Productprice_entity/entityfields/attributes/children/filteredattributes_param/valueProcess.js
@@ -1,3 +1,3 @@
 import("system.db");
 import("system.result");
-result.object(db.array(db.ROW, "select AB_ATTRIBUTEID from AB_ATTRIBUTE where ATTRIBUTE_PARENT_ID = 'ab545654-1fce-4993-b763-0ec469781302'"));
\ No newline at end of file
+result.object(db.array(db.ROW, "select AB_ATTRIBUTEID from AB_ATTRIBUTE where ATTRIBUTE_PARENT_ID = 'ab545654-1fce-4993-b763-0ec469781302'"));
diff --git a/entity/SalesprojectAnalyses_entity/recordcontainers/jdito/contentProcess.js b/entity/SalesprojectAnalyses_entity/recordcontainers/jdito/contentProcess.js
index b6d479b206e199c93b6ff335eea209f092f5760c..afcd4eaacbf83cd6a1329d9678895224751c2193 100644
--- a/entity/SalesprojectAnalyses_entity/recordcontainers/jdito/contentProcess.js
+++ b/entity/SalesprojectAnalyses_entity/recordcontainers/jdito/contentProcess.js
@@ -1,3 +1,4 @@
+import("Sql_lib");
 import("system.vars");
 import("system.datetime");
 import("system.db");
@@ -10,9 +11,14 @@ import("KeywordRegistry_basic");
     
 // load data
 
-var phases = db.table("select KEYID, AB_KEYWORD_ENTRY.TITLE, count(PHASE), AB_KEYWORD_ENTRY.SORTING \n\
-from SALESPROJECT join AB_KEYWORD_ENTRY on KEYID = PHASE and  CONTAINER  = 'SalesprojectPhase' and SORTING <> 7 \n\
-group by KEYID, AB_KEYWORD_ENTRY.TITLE, AB_KEYWORD_ENTRY.SORTING order by SORTING");
+var phases = newSelect("KEYID, AB_KEYWORD_ENTRY.TITLE, count(PHASE), AB_KEYWORD_ENTRY.SORTING")
+    .from("SALESPROJECT")
+    .join("AB_KEYWORD_ENTRY", newWhere("KEYID = PHASE")
+        .and("AB_KEYWORD_ENTRY.CONTAINER", $KeywordRegistry.salesprojectPhase())
+        .and("SORTING != 7"))
+    .groupBy("KEYID, AB_KEYWORD_ENTRY.TITLE, AB_KEYWORD_ENTRY.SORTING")
+    .orderBy("SORTING")
+    .table();
 
 for(i = 0; i < phases.length; i++){
     if(phases[i][1] == "${SALESPROJECT_OFFER}"){
diff --git a/entity/SerialLetter_entity/SerialLetter_entity.aod b/entity/SerialLetter_entity/SerialLetter_entity.aod
index c5508c8d60e7373f2ef0230f50d3aba3221defac..ea1946f6742ef1667bab4bb32df0a0024cae77c3 100644
--- a/entity/SerialLetter_entity/SerialLetter_entity.aod
+++ b/entity/SerialLetter_entity/SerialLetter_entity.aod
@@ -95,6 +95,7 @@
     </entityConsumer>
     <entityField>
       <name>bindata</name>
+      <title>Custom template</title>
       <contentType>FILE</contentType>
     </entityField>
     <entityField>
diff --git a/entity/Timetracking_entity/entityfields/totaltime/valueProcess.js b/entity/Timetracking_entity/entityfields/totaltime/valueProcess.js
index 0f403dcc2e977f172268995abf19ed2fdf770d2d..1bb9780412cbcb03a974eba91c95fd27c0c609af 100644
--- a/entity/Timetracking_entity/entityfields/totaltime/valueProcess.js
+++ b/entity/Timetracking_entity/entityfields/totaltime/valueProcess.js
@@ -1,7 +1,9 @@
-import("system.db");
+import("Sql_lib");
 import("system.vars");
 import("system.result");
 
-var minutes = db.cell("select sum(TRACKINGMINUTES) from TIMETRACKING");
+var minutes = newSelect("sum(TRACKINGMINUTES)")
+    .from("TIMETRACKING")
+    .cell(false, "0");
 
 result.string(minutes);
\ No newline at end of file
diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
index d6cdf3c96e51fcc05e67a251fd33e7daf89462ac..fe5a2b04ac5ca103c83313e02187862056887b33 100644
--- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
+++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod
@@ -77,6 +77,10 @@
       <key>Long string value</key>
       <value>Langer String-Wert</value>
     </entry>
+    <entry>
+      <key>Custom template</key>
+      <value>Benutzerdefinierte Vorlage</value>
+    </entry>
     <entry>
       <key>Attribute groups can't be selected</key>
       <value>Eigenschafsgruppen können nicht verwendet werden</value>
diff --git a/neonView/DuplicateScannerEdit_view/DuplicateScannerEdit_view.aod b/neonView/DuplicateScannerEdit_view/DuplicateScannerEdit_view.aod
index e2fb8e4936f508a0d291b4d16c92c62255c144c2..eee2435f8925e4b208371d58bc9dc3aa29e214ee 100644
--- a/neonView/DuplicateScannerEdit_view/DuplicateScannerEdit_view.aod
+++ b/neonView/DuplicateScannerEdit_view/DuplicateScannerEdit_view.aod
@@ -5,7 +5,6 @@
   <layout>
     <boxLayout>
       <name>layout</name>
-      <maxDirectionElements v="4" />
       <autoHeight v="false" />
     </boxLayout>
   </layout>
diff --git a/neonView/DuplicateScannerFilter_view/DuplicateScannerFilter_view.aod b/neonView/DuplicateScannerFilter_view/DuplicateScannerFilter_view.aod
index 8eaa47dd6f00979976bf8044ae325fcc3e7d6cb9..30ff1ec993d913da55b40d28a36c2f98bb4aa8a0 100644
--- a/neonView/DuplicateScannerFilter_view/DuplicateScannerFilter_view.aod
+++ b/neonView/DuplicateScannerFilter_view/DuplicateScannerFilter_view.aod
@@ -14,8 +14,8 @@
       <favoriteActionGroup3>RunActionGroup</favoriteActionGroup3>
       <entityField>#ENTITY</entityField>
       <isCreatable v="false" />
-      <isEditable v="false" />
       <isDeletable v="false" />
+      <isEditable v="false" />
       <columns>
         <neonTableColumn>
           <name>7508e984-6a0b-4ec6-ab49-452e2b54f76d</name>
diff --git a/neonView/DuplicateScannerIndexConfigEdit_view/DuplicateScannerIndexConfigEdit_view.aod b/neonView/DuplicateScannerIndexConfigEdit_view/DuplicateScannerIndexConfigEdit_view.aod
index 8bc3637c6673268cbfe6acc1be32a37a80888ab2..309e20a326817de5b9178bdb37f79576316f4c8f 100644
--- a/neonView/DuplicateScannerIndexConfigEdit_view/DuplicateScannerIndexConfigEdit_view.aod
+++ b/neonView/DuplicateScannerIndexConfigEdit_view/DuplicateScannerIndexConfigEdit_view.aod
@@ -3,9 +3,9 @@
   <name>DuplicateScannerIndexConfigEdit_view</name>
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <layout>
-    <boxLayout>
+    <noneLayout>
       <name>layout</name>
-    </boxLayout>
+    </noneLayout>
   </layout>
   <children>
     <genericMultipleViewTemplate>
diff --git a/neonView/DuplicateScannerPrefilterConfigEdit_view/DuplicateScannerPrefilterConfigEdit_view.aod b/neonView/DuplicateScannerPrefilterConfigEdit_view/DuplicateScannerPrefilterConfigEdit_view.aod
index 633cbd8fd946120f2c1f295a34ed1954046e8e9d..3108d1e689f0cd720809d834abd2db1e4eab0520 100644
--- a/neonView/DuplicateScannerPrefilterConfigEdit_view/DuplicateScannerPrefilterConfigEdit_view.aod
+++ b/neonView/DuplicateScannerPrefilterConfigEdit_view/DuplicateScannerPrefilterConfigEdit_view.aod
@@ -4,9 +4,9 @@
   <majorModelMode>DISTRIBUTED</majorModelMode>
   <isSmall v="false" />
   <layout>
-    <boxLayout>
+    <noneLayout>
       <name>layout</name>
-    </boxLayout>
+    </noneLayout>
   </layout>
   <children>
     <genericMultipleViewTemplate>
diff --git a/process/Campaign_lib/process.js b/process/Campaign_lib/process.js
index ac2b7375ac4592d35e284339a65f2d9632845e5d..c364beebc0e862195222c020a898284203cbb85e 100644
--- a/process/Campaign_lib/process.js
+++ b/process/Campaign_lib/process.js
@@ -191,12 +191,11 @@ CampaignUtils.openNewCampaignView = function()
 
 CampaignUtils.getDefaultCampaignStep = function(pCampaignId)
 {
-    let selectQuery = "select CAMPAIGNSTEPID from CAMPAIGNSTEP " +
-                      "where CAMPAIGNSTEP.CAMPAIGN_ID = '" + pCampaignId + "' " +
-                      "order by CAMPAIGNSTEP.SORTING asc";
-    
-    
-    return db.cell(selectQuery)   
+    return newSelect("CAMPAIGNSTEPID")
+        .from("CAMPAIGNSTEP")
+        .where("CAMPAIGNSTEP.CAMPAIGN_ID", pCampaignId)
+        .orderBy("CAMPAIGNSTEP.SORTING asc")
+        .cell();
 }
 
 CampaignUtils.getCampaignStartDate = function(pCapmaignId)
@@ -260,8 +259,10 @@ CampaignUtils.deleteCampaignData = function(pCampaignId)
     if(pCampaignId == null || pCampaignId == "")
         return;
     
-    let allStepIdsOfCampaignQuery = "select CAMPAIGNSTEPID from CAMPAIGNSTEP where CAMPAIGN_ID = '" + pCampaignId + "'";
-    let campaignStepIds = db.array(db.COLUMN, allStepIdsOfCampaignQuery);
+    let campaignStepIds = newSelect("CAMPAIGNSTEPID")
+        .from("CAMPAIGNSTEP")
+        .where("CAMPAIGNSTEP.CAMPAIGN_ID", pCampaignId)
+        .arrayColumn();
     
     campaignStepIds.forEach(function (campaignStepId) 
     {
@@ -342,70 +343,77 @@ CampaignUtils.GetContactIdsNotInCampaignByRowIds = function(pCampaignId, pPartic
 {
     let rowIdsAsRay = _CampaignUtils._convertToSqlValuesList(pParticipantRowIds);
     
-    let query = "select CONTACT.CONTACTID from CONTACT"
-    + " where CONTACT.CONTACTID in " + rowIdsAsRay
-    + " and CONTACT.CONTACTID not in"
-    + " (select CAMPAIGNPARTICIPANT.CONTACT_ID from CAMPAIGNPARTICIPANT"
-    + " where CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "')";
-
-    return db.array(db.COLUMN, query)
+    return newSelect("CONTACT.CONTACTID")
+        .from("CONTACT")
+        .where("CONTACT.CONTACTID", rowIdsAsRay, SqlBuilder.IN())
+        .and("CONTACT.CONTACTID", 
+            newSelect("CAMPAIGNPARTICIPANT.CONTACT_ID")
+            .from("CAMPAIGNPARTICIPANT")
+            .where("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", pCampaignId)
+            , SqlBuilder.NOT_IN())
+        .arrayColumn();
 }
 
 CampaignUtils.GetContactIdsNotInCampaignByCondition = function(pCampaignId, pCondition, pRightJoinContacts)
 {
-    let query = "select CONTACT.CONTACTID from PERSON"
+    let query = newSelect("CONTACT.CONTACTID").from("PERSON");
     
-    if(pRightJoinContacts == "true")
-        query += " right"
+    if (pRightJoinContacts == "true")
+        query.rightJoin("CONTACT", "CONTACT.PERSON_ID = PERSON.PERSONID");
+    else
+        query.join("CONTACT", "CONTACT.PERSON_ID = PERSON.PERSONID");
     
-    query += " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)"
-    + " join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID)"
-    + " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)"
-    + " where CONTACT.CONTACTID not in"
-    + " (select CAMPAIGNPARTICIPANT.CONTACT_ID from CAMPAIGNPARTICIPANT where"
-    + " CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "')";
+    query.join("ORGANISATION", "ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID")
+        .leftJoin("ADDRESS", "ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID")
+        .where("CONTACT.CONTACTID", 
+            newSelect("CAMPAIGNPARTICIPANT.CONTACT_ID")
+            .from("CAMPAIGNPARTICIPANT")
+            .where("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", pCampaignId)
+            , SqlBuilder.NOT_IN()
+        );
     
     if(pCondition != "")
-        query += " and " + pCondition;
+        query.and(pCondition);
 
-    return db.array(db.COLUMN, query);
+    return query.arraColumn();
 }
 
 CampaignUtils.GetContactIdsInCampaignByCondition = function(pCampaignId, pCondition, pRightJoinContacts)
 {
-    let query = "select CONTACT.CONTACTID from CONTACT"
+    let query = newSelect("CONTACT.CONTACTID").from("CONTACT");
     
 //    if(pRightJoinContacts == "true")
 //        query += " right"
     
-    query += " left join PERSON on (CONTACT.PERSON_ID = PERSON.PERSONID)"
-    + " left join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID)"
-    + " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)"
-    + " left join CAMPAIGNPARTICIPANT on CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID"
-    + " where " + pCondition
-    + " and CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "'";
+    query.leftJoin("PERSON", "CONTACT.PERSON_ID = PERSON.PERSONID")
+        .leftJoin("ORGANISATION", "ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID")
+        .leftJoin("ADDRESS", "ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID")
+        .leftJoin("CAMPAIGNPARTICIPANT", "CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID")
+        .where(pCondition)
+        .and("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", pCampaignId);
 
-    return db.array(db.COLUMN, query);
+    return query.arrayColumn();
 }
 
 CampaignUtils.GetContactCountByCondition = function(pCondition, pLookInCampaignOnly, pRightJoinContacts)
 {
-    let query = "select count(*) from PERSON"
+    let query = newSelect("count(*)").from("PERSON");
     
     if(pRightJoinContacts == "true")
-        query += " right"
+        query.rightJoin("CONTACT", "CONTACT.PERSON_ID = PERSON.PERSONID");
+    else
+        query.join("CONTACT", "CONTACT.PERSON_ID = PERSON.PERSONID");
     
-    query += " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)"
-    query += " join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID)"
-    query += " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)"
+    query.join("ORGANISATION", "ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID");
+    query.leftJoin("ADDRESS", "ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID");
                 
     if(pLookInCampaignOnly == "true")
-        query += " left join CAMPAIGNPARTICIPANT on CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID";
+        query.leftJoin("CAMPAIGNPARTICIPANT", "CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID");
     
     if(pCondition != "")
-        query += " where " + pCondition;
+        query.where(pCondition)
     
-    return db.cell(query);
+    return query.cell();
 }
 
 /**
@@ -459,22 +467,19 @@ function _CampaignUtils() {}
 
 _CampaignUtils._selectFromContactWithJoin = function(pSelectFields, pCampaignId, pWhereCondition)
 {
-    let query = "select " + pSelectFields + " from PERSON"
-                + " join CONTACT on (CONTACT.PERSON_ID = PERSON.PERSONID)"
-                + " join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID)"
-                + " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)";
-    
-    if(pWhereCondition != "")
-    {
-        query += " where " + pWhereCondition;
-        query += " and CONTACT.CONTACTID not in" 
-                + " (select CONTACT_ID from CAMPAIGNPARTICIPANT"
-                + " where CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "')";
-    }
-    else
-        query += " where CONTACT.CONTACTID not in" 
-                + " (select CONTACT_ID from CAMPAIGNPARTICIPANT"
-                + " where CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "')";
+    let query = newSelect(pSelectFields)
+        .from("PERSON")
+        .join("CONTACT", "CONTACT.PERSON_ID = PERSON.PERSONID")
+        .join("ORGANISATION", "ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID")
+        .leftJoin("ADDRESS", "ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID")
+        .where("CONTACT.CONTACTID", 
+            newSelect("CONTACT_ID")
+            .from("CAMPAIGNPARTICIPANT")
+            .where("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", pCampaignId)
+            , SqlBuilder.NOT_IN());
+    
+    if (pWhereCondition != "")
+        query.and(pWhereCondition);
     
     return query;
 }
diff --git a/process/Date_lib/process.js b/process/Date_lib/process.js
index 60a391e0f50071c1c2390d35d5a2b0874de60ba6..18a7b2b1883a041e4f84cb9e14c950073aa98381 100644
--- a/process/Date_lib/process.js
+++ b/process/Date_lib/process.js
@@ -155,4 +155,12 @@ DateUtils.formatDurationFromStartTillEnd = function(pStartTime, pEndTime, pLocal
 DateUtils.validateNotInFuture = function (pDate)
 {
     return Number(datetime.clearTime(pDate)) <= Number(vars.get("$sys.today"));
+}
+
+/**
+ * @return {number} the current year
+ */
+DateUtils.getCurrentYear = function ()
+{
+    return parseInt(datetime.toDate(vars.get("$sys.date"), "yyyy"));
 }
\ No newline at end of file
diff --git a/process/Email_lib/process.js b/process/Email_lib/process.js
index 64ac00725286dd7d5d051590a44b5c06d0ff4ad2..4354a818371839035a9a6140cb0362c8d119b1c6 100644
--- a/process/Email_lib/process.js
+++ b/process/Email_lib/process.js
@@ -107,13 +107,8 @@ Email.fromRFC = function (pBase64RFC)
 Email.fromTemplate = function (pTemplateId, pContactId, pBindata)
 {
     var template;
-    if (pBindata && pBindata.isFilled())
-    {
-        if (BulkMailUtils.isValidMimeType(pBindata.mimeType))
-        {
-            template = new DocumentTemplate(pBindata.bindata, DocumentTemplate.types.fromMimeType(pBindata.mimeType), pBindata.filename, true);
-        }
-    }
+    if (pBindata && pBindata.isFilled() && BulkMailUtils.isValidMimeType(pBindata.mimeType))
+        template = new DocumentTemplate(pBindata.bindata, DocumentTemplate.types.fromMimeType(pBindata.mimeType), pBindata.filename, true);
     else
         template = DocumentTemplate.loadTemplate(pTemplateId);
         
@@ -210,6 +205,9 @@ Email.prototype._newMailObject = function()
         mail.clearRecipients(mailId, mail.RECIPIENT_BCC);
     }
     
+    if (this.sender)
+        mail.setSender(mailId, this.sender);
+        
     if (this.toRecipients.length)
         mail.addRecipients(mailId, mail.RECIPIENT_TO, this.toRecipients);
 
diff --git a/process/Loghistory_lib/process.js b/process/Loghistory_lib/process.js
index 88d811340f29cd9caaa27a4cb6a97a28be0a001b..4a8ea67de390cfd88ea4ff4a85ae897203a06fe8 100644
--- a/process/Loghistory_lib/process.js
+++ b/process/Loghistory_lib/process.js
@@ -130,7 +130,7 @@ LogHistoryExecutor.prototype.execute = function ()
         }
         if (this.sqlAction == 'U')
         {
-            var ids = db.array(db.ROW, "select " + conf.IDs.join(", ") + " from " + this.affectedTable + " where " + this.affectedTable + "ID = '" + idvalue + "'");
+            var ids = newSelect(conf.IDs).from(this.affectedTable).where([this.affectedTable, this.affectedTable + "ID"], idvalue).arrayRow();
             idvalue = ids[0];
             var oldid =  ids[1];
             if (oldvalues[conf.IDs[1]]) oldid =  oldvalues[conf.IDs[1]];
@@ -195,7 +195,7 @@ LogHistoryExecutor.prototype.execute = function ()
         }
         if (this.sqlAction == "U")
         {
-            for (var index in references) references[index].id = db.cell("select " + index + " from "  + this.affectedTable + " where " + primaryKey + " = '" + this.idValue + "'");
+            for (var index in references) references[index].id = newSelect(index).from(this.affectedTable).where([this.affectedTable, primaryKey], this.idValue).cell();
         }
     }
 
diff --git a/process/Neon_lib/process.js b/process/Neon_lib/process.js
index 037de6882493598ffab3c553f2efa866a9f37c68..a5eb0b3129038bb2d749b1afd2732e2c19d39dad 100644
--- a/process/Neon_lib/process.js
+++ b/process/Neon_lib/process.js
@@ -1,3 +1,4 @@
+import("Sql_lib");
 import("Date_lib");
 import("system.vars");
 import("system.datetime");
@@ -181,7 +182,7 @@ CopyModuleUtils.copyModule = function(pInputMapping)
             if(pCondition != undefined)
                 condition = pCondition;
 
-            var dbData = db.table("select " + cols.join(", ") + " from " + pModule + " where " + condition);
+            var dbData = newSelect(cols).from(pModule).where(condition).table();
 
             //map 2d-Array to Object { $rowNumber$: { $columnName$: { value: "valueInDB" } } }
             var DataObj = {};
diff --git a/process/ObjectRelation_lib/process.js b/process/ObjectRelation_lib/process.js
index 330272e687261fd31d763b68beab6cf5118683d8..447a67cf94ae7ba157153065a6c412b8448903df 100644
--- a/process/ObjectRelation_lib/process.js
+++ b/process/ObjectRelation_lib/process.js
@@ -23,80 +23,43 @@ function ObjectRelationUtils() {}
  */
 ObjectRelationUtils.getPossibleRelationTypes = function(pObjectTypes, pFullInfo, pOnlyFirstSide, pRelationTypeId, pDummyField)
 {
-    // TODO: use sql builder
-    
-    var sql = " from AB_OBJECTRELATIONTYPE main \n\
-            left join AB_OBJECTRELATIONTYPE type2 on (type2.AB_OBJECTRELATIONTYPEID <> main.AB_OBJECTRELATIONTYPEID and type2.RELATION_TYPE = main.RELATION_TYPE) ";
-    var cond = "";
-    
-    var params = [];
-    
-    if (pObjectTypes)
-    {
-        pObjectTypes.forEach(function(pObjectType)
-        {
-            if (!cond)
-                cond += "where ";
-            else
-                cond += " or ";
-            
-            cond += "case when type2.OBJECT_TYPE is null then main.OBJECT_TYPE else type2.OBJECT_TYPE end = ? ";
-            params.push([pObjectType, db.getColumnTypes("AB_OBJECTRELATIONTYPE", ["OBJECT_TYPE"])[0]]);
-        });
-    }
-    
-    if (pRelationTypeId)
-    {
-        if (!cond)
-            cond = "where ";
-        else
-            cond += " and ";
-        
-        cond += " main.AB_OBJECTRELATIONTYPEID = ? ";
-        params.push([pRelationTypeId, db.getColumnTypes("AB_OBJECTRELATIONTYPE", ["AB_OBJECTRELATIONTYPEID"])[0]]);
-    }
+    var sql = new SqlBuilder()
+        .from("AB_OBJECTRELATIONTYPE", "main")
+        .leftJoin("AB_OBJECTRELATIONTYPE", "type2.AB_OBJECTRELATIONTYPEID <> main.AB_OBJECTRELATIONTYPEID and type2.RELATION_TYPE = main.RELATION_TYPE", "type2")
+        .whereIfSet(["AB_OBJECTRELATIONTYPE", "OBJECT_TYPE", "type2"], pObjectTypes, "(case when # is null then main.OBJECT_TYPE else type2.OBJECT_TYPE end) in ?")
+        .andIfSet(["AB_OBJECTRELATIONTYPE", "AB_OBJECTRELATIONTYPEID", "main"], pRelationTypeId || null);
     
     if (pOnlyFirstSide == "1")
-    {
-        if (!cond)
-            cond = "where ";
-        else
-            cond += " and ";
-        
-        cond += " main.SIDE = 1 "
-    }
-    
-    sql += cond;
+        sql.and("main.SIDE = 1");
     
+    var fields = ["main.AB_OBJECTRELATIONTYPEID", "main.RELATION_TITLE"];
     // only id and title:
-    if (pFullInfo == undefined || pFullInfo == false)
-    {
-        sql = "select main.AB_OBJECTRELATIONTYPEID, main.RELATION_TITLE" + sql;
-    }
-    else
+    if (pFullInfo)
     {
-        sql = "select main.AB_OBJECTRELATIONTYPEID, main.RELATION_TITLE, main.RELATION_TYPE, \n\
-        case when type2.AB_OBJECTRELATIONTYPEID is null then 'same' \n\
-             when main.SIDE = 1 then 'normal'\n\
-             else 'reverse'\n\
-        end direction,\n\
-        main.HIERARCHY, \n\
-        ( case when type2.AB_OBJECTRELATIONTYPEID is null then main.OBJECT_TYPE " + // if type is 'same' (type2.AB_OBJECTRELATIONTYPEID is null) then use the same object type for dest as for source
-        "    else type2.OBJECT_TYPE end ) destObjectType, \n\
-        main.OBJECT_TYPE sourceObjectType, \n\
-        -- typeId of Object2\n\
-        case when main.SIDE = 1 then main.AB_OBJECTRELATIONTYPEID\n\
-             else type2.AB_OBJECTRELATIONTYPEID end objectrelationtypeId1,\n\
-        -- typeId of Object1\n\
-        case when type2.AB_OBJECTRELATIONTYPEID is null or main.SIDE = 2 then main.AB_OBJECTRELATIONTYPEID\n\
-             else type2.AB_OBJECTRELATIONTYPEID end objectrelationtypeId2, \n\
-        main.SIDE,\n\
-        case when type2.AB_OBJECTRELATIONTYPEID is  null then main.AB_OBJECTRELATIONTYPEID else type2.AB_OBJECTRELATIONTYPEID end,\n\
-        type2.RELATION_TITLE" + (pDummyField ? ", ''" : "") + ", main.ICON" + sql; // Icon is only saved in type1
+        fields = fields.concat([
+            "main.RELATION_TYPE",
+            "case when type2.AB_OBJECTRELATIONTYPEID is null then 'same' \n\
+                when main.SIDE = 1 then 'normal'\n\
+                else 'reverse'\n\
+                end direction",
+            "main.HIERARCHY",
+            "(case when type2.AB_OBJECTRELATIONTYPEID is null then main.OBJECT_TYPE " + // if type is 'same' (type2.AB_OBJECTRELATIONTYPEID is null) then use the same object type for dest as for source
+            "    else type2.OBJECT_TYPE end) destObjectType",
+            "main.OBJECT_TYPE sourceObjectType",
+            "-- typeId of Object2\n\
+            case when main.SIDE = 1 then main.AB_OBJECTRELATIONTYPEID \n\
+                else type2.AB_OBJECTRELATIONTYPEID end objectrelationtypeId1",
+            "-- typeId of Object1\n\
+            case when type2.AB_OBJECTRELATIONTYPEID is null or main.SIDE = 2 then main.AB_OBJECTRELATIONTYPEID\n\
+                else type2.AB_OBJECTRELATIONTYPEID end objectrelationtypeId2",
+            "main.SIDE",
+            "case when type2.AB_OBJECTRELATIONTYPEID is null then main.AB_OBJECTRELATIONTYPEID else type2.AB_OBJECTRELATIONTYPEID end",
+            "type2.RELATION_TITLE", (pDummyField ? "''" : ""), "main.ICON" // Icon is only saved in type1
+        ]);
     }
        
     // full info:
-    return (db.table([sql, params]));
+    return sql.select(fields).table();
 }
 
 /**
diff --git a/process/Organisation_lib/process.js b/process/Organisation_lib/process.js
index d173872ccf02570cd9b4298e7795abbe0f64ee48..a5500b246465d5d168849d0303d1da8d6c96e1cc 100644
--- a/process/Organisation_lib/process.js
+++ b/process/Organisation_lib/process.js
@@ -20,6 +20,30 @@ import("KeywordRegistry_basic");
  */
 function OrgUtils() {}
 
+/**
+ * checks if a organisationid is the id of the dummy organisation "private"
+ * 
+ * @param {String} pOrganisationId the id that shall be checked
+ *
+ * @return {boolean} true if passed organisationid is organisationid of the dummy organisation "private"
+ */
+OrgUtils.isPrivateOrganisationId = function(pOrganisationId)
+{
+    //TODO: use this function everywhere instead of manual checks
+    return pOrganisationId.trim() == OrgUtils.getPrivateOrganisationId();
+}
+
+/**
+ * returns the image for a organisation
+ * 
+ * @return {String} hard coded organisationid of the dummy organisation "private"
+ */
+OrgUtils.getPrivateOrganisationId = function()
+{
+    //TODO: use this function everywhere instead of hardcoded organisationids "0"
+    return "0";
+}
+
 /**
  * returns the image for a organisation
  * 
diff --git a/process/Product_lib/process.js b/process/Product_lib/process.js
index 1c7f91318e380e29494e92336d82c25677160a6c..0f9cdab1cd739cf8cae1da29190d52726da19c49 100644
--- a/process/Product_lib/process.js
+++ b/process/Product_lib/process.js
@@ -540,9 +540,11 @@ Prod2ProdUtils.prototype.getParentProdIds = function()
 Prod2ProdUtils.prototype._initProd2ProdData = function()
 {
     if (this.data == undefined) {
-        this.data = db.table("select PROD2PRODID, DEST_ID, SOURCE_ID, QUANTITY, OPTIONAL, TAKEPRICE, PRODUCTCODE, PRODUCTID "
-                    + "from PROD2PROD join PRODUCT on PROD2PROD.SOURCE_ID = PRODUCTID "
-                    + "order by PRODUCTCODE ");
+        this.data = newSelect("PROD2PRODID, DEST_ID, SOURCE_ID, QUANTITY, OPTIONAL, TAKEPRICE, PRODUCTCODE, PRODUCTID")
+            .from("PROD2PROD")
+            .join("PRODUCT", "PROD2PROD.SOURCE_ID = PRODUCTID")
+            .orderBy("PRODUCTCODE")
+            .table();
     }
 }
 
diff --git a/process/Sql_lib/process.js b/process/Sql_lib/process.js
index c4f36ef31d4d9911ef728ef6459e91be86d5a00b..47ef865b350be92c7c9c83347144ebe12fe47419 100644
--- a/process/Sql_lib/process.js
+++ b/process/Sql_lib/process.js
@@ -987,6 +987,20 @@ SqlBuilder.NOT_EXISTS = function()
     return "not exists ?";
 }
 
+/**
+ * Constant-like function which provides a value for pCondition if you need a "year(#) = ?" statement.
+ * Make sure you use SQLTYPES.INTEGER as type.
+ * 
+ * @return {String} 
+ * 
+ * @example
+ * var cond = newWhere("FORECAST.DATE_START", DateUtils.getCurrentYear(), SqlBuilder.YEAR_EQUALS(), SQLTYPES.INTEGER)
+ */
+SqlBuilder.YEAR_EQUALS = function ()
+{
+    return (new SqlMaskingUtils().yearFromDate("#")) + " = ?";
+}
+
 /**
  * Throws an error if pValue is null, undefined or a SqlBuilder without condition (or if pValue is a $-variable: error if the result of it is null or undefined)<br/>
  * Also throws an error if pFieldOrCond is the only parameter and it is null<br/>
diff --git a/process/StandardObject_lib/process.js b/process/StandardObject_lib/process.js
index 772d1e21ee1a13df0cbed76d5b8c837ec682e8ef..6eaf4aa07bd1023fd90e769f333f6034cf5f7893 100644
--- a/process/StandardObject_lib/process.js
+++ b/process/StandardObject_lib/process.js
@@ -1,3 +1,5 @@
+import("Organisation_lib");
+import("Sql_lib");
 import("system.db");
 import("Keyword_lib");
 import("KeywordRegistry_basic");
@@ -110,12 +112,12 @@ StandardObject.prototype.onPersonValueChange = function (pSelectedOrganisationID
  * on a "random" basis: Which object gets first inserted will get the
  * place as standard.
  */
-StandardObject.prototype.onObjectInsert = function () {
+StandardObject.prototype.onObjectInsert = function (pIdToOverwrite) {
     this._assertObjectIdNotNull();
     this._assertScopeIdNotNull(); 
     
     if (this.objectType === StandardObject.CONST_OBJECT_ADDRESS()) {
-        this._onAddressInsert();
+        this._onAddressInsert(pIdToOverwrite);
     } else if (this.objectType === StandardObject.CONST_OBJECT_COMMUNICATION) {
         this._onCommunicationInsert();
     }
@@ -126,11 +128,11 @@ StandardObject.prototype.onObjectInsert = function () {
  * of the `Address` entity. This will set the standard address on the
  * contact if it's currently null.
  */
-StandardObject.prototype._onAddressInsert = function () {
+StandardObject.prototype._onAddressInsert = function (pIdToOverwrite) {
     // Assert
     this._assertObjectType(StandardObject.CONST_OBJECT_ADDRESS());
     
-    if (!this._hasContactStandardAddress(this.scopeID)) {
+    if (!this._hasContactStandardAddress(this.scopeID, pIdToOverwrite)) {
         this._setContactStandardAddress(this.objectID, this.scopeID);
     }
 }
@@ -189,15 +191,17 @@ StandardObject.prototype.onCommunicationUpdate = function (pMediumID) {
  * it's currently working on a `Address` object.
  * 
  * @param {String} pContactID Contact ID to check.
+ * @param {String} [pIdToIgnore] if this address ID is found, act as if it was empty
  * @return {Boolean} If the contact ID has standard address.
  */
-StandardObject.prototype._hasContactStandardAddress = function (pContactID) {
+StandardObject.prototype._hasContactStandardAddress = function (pContactID, pIdToIgnore) {
     this._assertObjectType(StandardObject.CONST_OBJECT_ADDRESS());
     
-    var databaseResult = db.cell("select ADDRESS_ID from CONTACT"
-        + " where CONTACTID = '" + pContactID + "'");
-    
-    return databaseResult !== "";
+    var databaseResult = newSelect("ADDRESS_ID").from("CONTACT")
+        .where("CONTACT.CONTACTID", pContactID)
+        .cell();
+        
+    return databaseResult !== "" && databaseResult !== pIdToIgnore;
 }
 
 /**
@@ -217,7 +221,7 @@ StandardObject.prototype._setContactStandardAddress = function (pAddressID, pCon
         ["ADDRESS_ID"], 
         db.getColumnTypes("CONTACT", ["ADDRESS_ID"]), 
         [pAddressID], 
-        "CONTACTID = '" + pContactID + "'");
+        newWhere("CONTACT.CONTACTID", pContactID).build());
 }
 
 /**
@@ -227,13 +231,13 @@ StandardObject.prototype._setContactStandardAddress = function (pAddressID, pCon
  * @return Standard address of the organisation or null.
  */
 StandardObject.prototype._getCompanyStandardAddress = function (pOrganisationID) {
-    var addressIdResult = db.cell("select ADDRESS_ID from CONTACT"
-        + " where ORGANISATION_ID = '" + pOrganisationID + "'"
-        + " and ADDRESS_ID is not null and PERSON_ID is null");
-    
-    if (addressIdResult === "")
+    if (OrgUtils.isPrivateOrganisationId(pOrganisationID))
         return null;
-    return addressIdResult;
+    return newSelect("ADDRESS_ID")
+        .from("CONTACT")
+        .where("CONTACT.ORGANISATION_ID", pOrganisationID)
+        .and("ADDRESS_ID is not null and PERSON_ID is null")
+        .cell() || null;
 }
 
 /**
@@ -246,12 +250,15 @@ StandardObject.prototype._getCompanyStandardAddress = function (pOrganisationID)
  * medium category.
  */
 StandardObject.prototype._hasStandardCommunicationByMedium = function (pContactID, pMediumCategory) {   
-    var dbResult = db.array(db.COLUMN, "select CHAR_VALUE from COMMUNICATION"
-        + " left join AB_KEYWORD_ENTRY on KEYID = MEDIUM_ID"
-        + " left join AB_KEYWORD_ATTRIBUTERELATION on AB_KEYWORD_ENTRY_ID = AB_KEYWORD_ENTRYID"
-        + " where ISSTANDARD = 1 and CONTACT_ID = '" + pContactID + "' and KEYID in ('" + CommUtil.getMediumIdsByCategory(pMediumCategory).join("', '") +  "')");
-    
-    return dbResult.indexOf(pMediumCategory) !== -1;
+    return newSelect("CHAR_VALUE")
+        .from("COMMUNICATION")
+        .leftJoin("AB_KEYWORD_ENTRY", "KEYID = MEDIUM_ID")
+        .leftJoin("AB_KEYWORD_ATTRIBUTERELATION", "AB_KEYWORD_ENTRY_ID = AB_KEYWORD_ENTRYID")
+        .where("ISSTANDARD = 1")
+        .and("COMMUNICATION.CONTACT_ID", pContactID)
+        .and("AB_KEYWORD_ENTRY.KEYID", CommUtil.getMediumIdsByCategory(pMediumCategory), SqlBuilder.IN())
+        .arrayColumn()
+        .indexOf(pMediumCategory) !== -1;
 }
 
 /**
@@ -283,7 +290,7 @@ StandardObject.prototype._setStandardCommunication = function (pCommunicationID,
         ["ISSTANDARD"], 
         db.getColumnTypes("COMMUNICATION", ["ISSTANDARD"]), 
         [pValue], 
-        "COMMUNICATIONID = '" + pCommunicationID + "'");
+        newWhere("COMMUNICATION.COMMUNICATIONID", pCommunicationID).build());
 }
 
 /**
@@ -293,7 +300,7 @@ StandardObject.prototype._setStandardCommunication = function (pCommunicationID,
  * @return The contact ID.
  */
 StandardObject.prototype._getContactIdByCommunication = function (pCommunicationID) {
-    return db.cell("select CONTACT_ID from COMMUNICATION where COMMUNICATIONID = '" + pCommunicationID + "'");
+    return newSelect("CONTACT_ID").from("COMMUNICATION").where("COMMUNICATION.COMMUNICATIONID", pCommunicationID).cell();
 }
 
 StandardObject.prototype._isOrganisationAddress = function (pAddressID) {
@@ -307,7 +314,7 @@ StandardObject.prototype._isOrganisationAddress = function (pAddressID) {
  * @return The contact ID.
  */
 StandardObject.isOrganisationAddress = function (pAddressID) {
-    var contactID = db.cell("select CONTACTID from CONTACT where ADDRESS_ID = '" + pAddressID + "'");
+    var contactID = newSelect("CONTACTID").from("CONTACT").where("CONTACT.ADDRESS_ID", pAddressID).cell();
     
     if (!contactID)
         return false;