Skip to content
Snippets Groups Projects
Commit 20231ce0 authored by Johannes Goderbauer's avatar Johannes Goderbauer
Browse files

Merge branch '1048420_FixDuplicates' into '2020.0'

1048420, 1052262, 1048690

See merge request xrm/basic!143

(cherry picked from commit cad0c57e)

2f8afb14 [Projekt: Entwicklung - Neon][TicketNr.: 1048690][Reiter Beziehungen in der Firma]
67c72553 zwischencommit
b4ef5e07 [Projekt: Entwicklung - Neon][TicketNr.: 1052262][Firmen und Personen können nicht gelöscht werden]
53deb0a0 [Projekt: Entwicklung - Neon][TicketNr.: 1048420][Dublette/ Kontakt:...
64f98d05 [Projekt: Entwicklung - Neon][TicketNr.: 1048420][Dublette/ Kontakt:...
parent d79f0734
No related branches found
No related tags found
No related merge requests found
import("system.logging");
import("system.db");
import("system.translate");
import("system.result");
......@@ -44,12 +43,12 @@ else if(vars.exists("$local.idvalues") && vars.get("$local.idvalues") && vars.ge
if (uidParam && uidParam.includes("[")) // "[" -> is JSON
{
// Load one by uid. Basically the data to return is also encoded in the uid itself -> no extra data loading is needed.
let uid = JSON.parse(uidParam);
var uid = JSON.parse(uidParam);
// if objectRelationTypeId is a string it is a relation node and no Grouping
if (uid != null && typeof uid[UID.objectRelationTypeId] == "string")
{
let relationTypeData = ObjectRelationUtils.getRelationType(uid[UID.objectRelationTypeId]);
var relationTypeData = ObjectRelationUtils.getRelationType(uid[UID.objectRelationTypeId]);
_insertEntry(tree, _getEntryData(uid[UID.objectId], relationTypeData[3], relationTypeData[7], relationTypeData[8], undefined, false,
uid[UID.objectRelationId]), "", 0, uid[UID.otherObjectType], relationTypeData[10], relationTypeData[12], relationTypeData[4]);
}
......
......@@ -2,24 +2,24 @@ import("system.db");
import("Employee_lib");
import("KeywordRegistry_basic");
import("ActivityTask_lib");
import("system.logging");
import("system.vars");
import("system.neon");
import("DuplicateScanner_lib");
let targetContactId = vars.get("$param.DuplicateCurrentContactId_param");
let sourceContactId = vars.get("$sys.selection");
logging.log("targetContactId -> " + targetContactId);
logging.log("sourceContactId -> "+ sourceContactId);
var targetContactId = vars.get("$param.DuplicateCurrentContactId_param");
var sourceContactIdArray = vars.get("$sys.selection");
var sourceContactId = sourceContactIdArray[0];
//todo the actual merge ought to happen in a separate view where the contact infos can be merged manually by the user.
let mergeSuccess = DuplicateScannerUtils.MergePerson(sourceContactId, targetContactId);
var mergeSuccess = DuplicateScannerUtils.MergePerson(sourceContactId, targetContactId);
if(mergeSuccess)
{
let currentContactId = EmployeeUtils.getCurrentContactId();
var currentContactId = EmployeeUtils.getCurrentContactId();
if(currentContactId == null)
currentContactId = "";
DuplicateScannerUtils.CreateMergeSuccessActivity(sourceContactId, targetContactId, currentContactId, "Person");
neon.refreshAll();
// openContext due to the fact, that openContext will lead to an error 'due'cause it's trying to load the already opened preview
// of the duplicateContact which just got deleted = nullpointException
neon.openContext("Person", null, [targetContactId], neon.OPERATINGSTATE_VIEW, null, null);
}
\ No newline at end of file
......@@ -468,6 +468,8 @@ AttributeRelationUtils.selectAttributeValue = function (pAttributeId, pValueMap,
type[0] = type[0].trim();
var field = AttributeTypeUtil.getDatabaseField(type[0]);
var value = pValueMap[field];
if(value == undefined)
return "";
if (pGetViewValue && type[0] == $AttributeTypes.COMBO)
{
value = newSelect("ATTRIBUTE_NAME")
......
......@@ -50,18 +50,20 @@ DuplicateScannerUtils.loadFilters = function(pFilterName, pTargetEntity)
*/
DuplicateScannerUtils.DeleteCachedDuplicate = function(pDuplicateId)
{
let query = newSelect("count(ID), CLUSTERID from DUPLICATECLUSTERS")
var query = newSelect("count(ID), CLUSTERID")
.from("DUPLICATECLUSTERS")
.where("DUPLICATECLUSTERS.CLUSTERID", newSelect("CLUSTERID")
.from("DUPLICATECLUSTERS")
.where("DUPLICATECLUSTERS.DUPLICATEID", pDuplicateId),
.where("DUPLICATECLUSTERS.DUPLICATEID", pDuplicateId).build(),
SqlBuilder.IN())
.and("DUPLICATECLUSTERS.DUPLICATEID", pDuplicateId, SqlBuilder.NOT_EQUAL())
.groupBy("CLUSTERID");
let coundAndClusterId = db.array(db.ROW, query);
let countDuplicatesInClusterWithoutParameterId = coundAndClusterId[0];
let clusterId = coundAndClusterId[1];
var countAndClusterId = query.arrayRow();
let countDuplicatesInClusterWithoutParameterId = countAndClusterId[0];
let clusterId = countAndClusterId[1];
//If only one duplicate would be remaining,
//the whole cluster has to be deleted because there are no more duplicates.
......@@ -635,9 +637,9 @@ DuplicateScannerUtils.TranslateEntityToIndexFields = function(pEntityName, pEnti
*/
DuplicateScannerUtils.MergePerson = function(pSourceContactId, pTargetContactId)
{
let updateStatementsCurrentAlias = [];
let updateStatementsSystemAlias = [];
let deleteStatements = [];
var updateStatementsCurrentAlias = [];
var updateStatementsSystemAlias = [];
var deleteStatements = [];
var sourcePersonId = newSelect("PERSON_ID")
.from("CONTACT")
......@@ -650,15 +652,15 @@ DuplicateScannerUtils.MergePerson = function(pSourceContactId, pTargetContactId)
updateStatementsCurrentAlias = updateStatementsCurrentAlias.concat(_DuplicateScannerUtils._buildUpdateContactIdStatements(tableInfosCurrentAlias, pSourceContactId, pTargetContactId));
updateStatementsCurrentAlias = updateStatementsCurrentAlias.concat(_DuplicateScannerUtils._buildUpdateAttachParticipantsToNewContactQuery("CAMPAIGNPARTICIPANT", "CONTACT_ID", "CAMPAIGN_ID", pSourceContactId, pTargetContactId));
updateStatementsSystemAlias = updateStatementsSystemAlias.concat(_DuplicateScannerUtils._buildUpdateContactIdStatements(tableInfosSystemAlias, pSourceContactId, pTargetContactId));
updateStatementsSystemAlias = updateStatementsSystemAlias.concat(_DuplicateScannerUtils._buildUpdateContactIdStatements(tableInfosSystemAlias, pSourceContactId, pTargetContactId, SqlUtils.getSystemAlias()));
deleteStatements = deleteStatements.concat(_DuplicateScannerUtils._buildDeleteRemoveObsoleteParticipantsRecordsQuery("CAMPAIGNPARTICIPANT", "CONTACT_ID", "CAMPAIGN_ID", pSourceContactId, pTargetContactId));
deleteStatements = deleteStatements.concat(_DuplicateScannerUtils._buildDeletePersonAndContactQuery(sourcePersonId, pSourceContactId));
deleteStatements = deleteStatements.concat(_DuplicateScannerUtils._buildDeleteCachedUnrelatedDuplicateQuery(pSourceContactId));
let affectedRowsCurrentAlias = db.updates(updateStatementsCurrentAlias);
let affectedRowsSystemAlias = db.updates(updateStatementsSystemAlias, SqlUtils.getSystemAlias());
let deletedRows = db.deletes(deleteStatements)
var affectedRowsCurrentAlias = db.updates(updateStatementsCurrentAlias);
var affectedRowsSystemAlias = db.updates(updateStatementsSystemAlias, SqlUtils.getSystemAlias());
var deletedRows = db.deletes(deleteStatements)
DuplicateScannerUtils.DeleteCachedDuplicate(pSourceContactId);
......@@ -1124,26 +1126,26 @@ _DuplicateScannerUtils._getIgnoreSourceRecordPattern = function(pRecordIdValueTo
return "( +( -" + indexsearch.FIELD_ID + ":(" + pRecordIdValueToIgnore + ") ) ";
}
_DuplicateScannerUtils._buildUpdateContactIdStatements = function(pTableInfos, pSourceContactId, pTargetContactId)
_DuplicateScannerUtils._buildUpdateContactIdStatements = function(pTableInfos, pSourceContactId, pTargetContactId, pAlias)
{
let statements = [];
for (let i = 0; i < pTableInfos.length; i++)
{
let tableInfo = pTableInfos[i];
let updateStatement = _DuplicateScannerUtils._buildStatement(tableInfo, pSourceContactId, pTargetContactId);
let updateStatement = _DuplicateScannerUtils._buildStatement(tableInfo, pSourceContactId, pTargetContactId, pAlias);
statements.push(updateStatement);
}
return statements;
}
_DuplicateScannerUtils._buildStatement = function(pTableinfos, pSourceContactId, pTargetContactId)
_DuplicateScannerUtils._buildStatement = function(pTableinfos, pSourceContactId, pTargetContactId, pAlias)
{
let tableName = pTableinfos[INDEX_TABLE_NAME];
let columnName = pTableinfos[INDEX_COLUMN_NAME];
let additionalCondition = pTableinfos[INDEX_CONDITION];
let condition = newWhere([tableName, columnName], pSourceContactId);
let condition = newWhere([tableName, columnName], pSourceContactId, undefined, undefined, pAlias);
if(additionalCondition != "")
condition.and(additionalCondition);
......
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