Skip to content
Snippets Groups Projects
Commit 2c715936 authored by Martin Groppe's avatar Martin Groppe
Browse files

Merge branch 'm_1082318_commRestrictionUsages' into '2021.1'

1082318 use communication settings in campaignParticipant

See merge request xrm/basic!1072
parents f0b83d0a 158fd744
No related branches found
No related tags found
No related merge requests found
import("system.vars"); import("system.vars");
import("Contact_lib"); import("Contact_lib");
import("Sql_lib");
import("system.result"); import("system.result");
import("MarketingCondition_lib");
// Now show warning always, if any commrestriction exists. No matter which medium the current step has. // Now show warning always, if any commrestriction exists. No matter which medium the current step has.
result.string("(" + ContactUtils.getCommRestrictionCount(undefined, vars.get("$sys.date")) + ")"); var condition = new CommunicationSettingsCondition()
\ No newline at end of file .anyMedium()
.rejected()
.existSettings()
.buildCondition();
result.string(condition.toString());
\ No newline at end of file
...@@ -14,8 +14,8 @@ new AttributeRelationQuery(contactId, null, ContextUtils.getCurrentContextId()) ...@@ -14,8 +14,8 @@ new AttributeRelationQuery(contactId, null, ContextUtils.getCurrentContextId())
newWhere("COMMUNICATION.CONTACT_ID", contactId).deleteData(); newWhere("COMMUNICATION.CONTACT_ID", contactId).deleteData();
newWhere("ADDRESS.CONTACT_ID", contactId).deleteData(); newWhere("ADDRESS.CONTACT_ID", contactId).deleteData();
newWhere("COMMRESTRICTION.CONTACT_ID", contactId).deleteData(); newWhere("COMMUNICATIONSETTINGS.CONTACT_ID", contactId).deleteData();
newWhere("CLASSIFICATIONSTORAGE.OBJECT_ROWID", vars.get("$field.CONTACTID")).deleteData(); newWhere("CLASSIFICATIONSTORAGE.OBJECT_ROWID", contactId).deleteData();
newWhere("CLASSIFICATION.OBJECT_ROWID", vars.get("$field.CONTACTID")).deleteData(); newWhere("CLASSIFICATION.OBJECT_ROWID", contactId).deleteData();
WorkflowSignalSender.deleted(); WorkflowSignalSender.deleted();
\ No newline at end of file
...@@ -6,17 +6,18 @@ import("system.vars"); ...@@ -6,17 +6,18 @@ import("system.vars");
import("DuplicateScanner_lib"); import("DuplicateScanner_lib");
var contactId = vars.get("$field.CONTACTID"); var contactId = vars.get("$field.CONTACTID");
var context = ContextUtils.getCurrentContextId();
DuplicateScannerUtils.deleteHasDuplicateEntries("Person_entity", [contactId]); DuplicateScannerUtils.deleteHasDuplicateEntries("Person_entity", [contactId]);
new AttributeRelationQuery(contactId, null, ContextUtils.getCurrentContextId()) new AttributeRelationQuery(contactId, null, context)
.deleteAllAttributes(); .deleteAllAttributes();
newWhere("COMMUNICATION.CONTACT_ID", contactId).deleteData(); newWhere("COMMUNICATION.CONTACT_ID", contactId).deleteData();
newWhere("ADDRESS.CONTACT_ID", contactId).deleteData(); newWhere("ADDRESS.CONTACT_ID", contactId).deleteData();
newWhere("COMMRESTRICTION.CONTACT_ID", contactId).deleteData(); newWhere("COMMUNICATIONSETTINGS.CONTACT_ID", contactId).deleteData();
newWhere("AB_APPOINTMENTLINK.OBJECT_TYPE", "Person") newWhere("AB_APPOINTMENTLINK.OBJECT_TYPE", context)
.and("AB_APPOINTMENTLINK.OBJECT_ROWID", contactId).deleteData(); .and("AB_APPOINTMENTLINK.OBJECT_ROWID", contactId).deleteData();
newWhere("AB_ATTRIBUTERELATION.OBJECT_TYPE", "Person") newWhere("AB_ATTRIBUTERELATION.OBJECT_TYPE", context)
.and("AB_ATTRIBUTERELATION.OBJECT_ROWID", contactId).deleteData(); .and("AB_ATTRIBUTERELATION.OBJECT_ROWID", contactId).deleteData();
WorkflowSignalSender.deleted(); WorkflowSignalSender.deleted();
\ No newline at end of file
...@@ -16,8 +16,15 @@ function CommunicationSettingsCondition () ...@@ -16,8 +16,15 @@ function CommunicationSettingsCondition ()
this._channelIdSql = null; this._channelIdSql = null;
this._settingStatus = null; this._settingStatus = null;
this._existsOperator = SqlBuilder.EXISTS(); this._existsOperator = SqlBuilder.EXISTS();
this._useAnyMedium = false;
} }
/**
* Sets a sql expression for the contact id
*
* @param {String|SqlBuilder} pContactIdSql sql field or expression to get the contactId
* @return {CommunicationSettingsCondition} current object
*/
CommunicationSettingsCondition.prototype.contactIdField = function (pContactIdSql) CommunicationSettingsCondition.prototype.contactIdField = function (pContactIdSql)
{ {
this._contactIdSql = pContactIdSql; this._contactIdSql = pContactIdSql;
...@@ -25,6 +32,12 @@ CommunicationSettingsCondition.prototype.contactIdField = function (pContactIdSq ...@@ -25,6 +32,12 @@ CommunicationSettingsCondition.prototype.contactIdField = function (pContactIdSq
return this; return this;
} }
/**
* Sets the contactId to get the communication settings from
*
* @param {String} pContactId contact id
* @return {CommunicationSettingsCondition} current object
*/
CommunicationSettingsCondition.prototype.contactId = function (pContactId) CommunicationSettingsCondition.prototype.contactId = function (pContactId)
{ {
this._contactId = pContactId; this._contactId = pContactId;
...@@ -32,12 +45,22 @@ CommunicationSettingsCondition.prototype.contactId = function (pContactId) ...@@ -32,12 +45,22 @@ CommunicationSettingsCondition.prototype.contactId = function (pContactId)
return this; return this;
} }
/**
* Makes the condition yield true if no communication setting exists
*
* @return {CommunicationSettingsCondition} current object
*/
CommunicationSettingsCondition.prototype.existNoSettings = function () CommunicationSettingsCondition.prototype.existNoSettings = function ()
{ {
this._existsOperator = SqlBuilder.NOT_EXISTS(); this._existsOperator = SqlBuilder.NOT_EXISTS();
return this; return this;
} }
/**
* Makes the condition yield true if at least one communication setting exists
*
* @return {CommunicationSettingsCondition} current object
*/
CommunicationSettingsCondition.prototype.existSettings = function () CommunicationSettingsCondition.prototype.existSettings = function ()
{ {
this._existsOperator = SqlBuilder.EXISTS(); this._existsOperator = SqlBuilder.EXISTS();
...@@ -120,12 +143,32 @@ CommunicationSettingsCondition.prototype.pending = function () ...@@ -120,12 +143,32 @@ CommunicationSettingsCondition.prototype.pending = function ()
return this; return this;
} }
/**
* Only fetch settings with the given status
*
* @param {String} pStatus staus that the communication settings need to have
* @return {CommunicationSettingsCondition} current object
*/
CommunicationSettingsCondition.prototype.status = function (pStatus) CommunicationSettingsCondition.prototype.status = function (pStatus)
{ {
this._settingStatus = pStatus; this._settingStatus = pStatus;
return this; return this;
} }
/**
* Fetch communication settings of any kind, regardless of medium or channel.
*
* @return {CommunicationSettingsCondition} current object
*/
CommunicationSettingsCondition.prototype.anyMedium = function ()
{
this._useAnyMedium = true;
this._medium = null;
this._channelType = null;
this._channelIdSql = null;
return this;
}
/** /**
* Builds a sub select for fetching the communication settings with the properies as configured. * Builds a sub select for fetching the communication settings with the properies as configured.
* *
...@@ -149,19 +192,22 @@ CommunicationSettingsCondition.prototype.buildSelect = function (pSelectFields) ...@@ -149,19 +192,22 @@ CommunicationSettingsCondition.prototype.buildSelect = function (pSelectFields)
sql.and("COMMUNICATIONSETTINGS.CONTACT_ID", this._contactId); sql.and("COMMUNICATIONSETTINGS.CONTACT_ID", this._contactId);
} }
var channelCondition = newWhere("COMMUNICATIONSETTINGS.CHANNEL_TYPE", $KeywordRegistry.communicationChannelType$global()); if (!this._useAnyMedium)
if (this._channelType)
{ {
var specificChannelCondition = newWhere("COMMUNICATIONSETTINGS.CHANNEL_TYPE", this._channelType) var channelCondition = newWhere("COMMUNICATIONSETTINGS.CHANNEL_TYPE", $KeywordRegistry.communicationChannelType$global());
.andIfSet("COMMUNICATIONSETTINGS.MEDIUM", this._medium); if (this._channelType)
if (this._channelIdSql)
{ {
specificChannelCondition.and(newWhere("COMMUNICATIONSETTINGS.CHANNEL_ID = " + this._channelIdSql) var specificChannelCondition = newWhere("COMMUNICATIONSETTINGS.CHANNEL_TYPE", this._channelType)
.or("COMMUNICATIONSETTINGS.CHANNEL_ID is null")); .andIfSet("COMMUNICATIONSETTINGS.MEDIUM", this._medium);
if (this._channelIdSql)
{
specificChannelCondition.and(newWhere("COMMUNICATIONSETTINGS.CHANNEL_ID = " + this._channelIdSql)
.or("COMMUNICATIONSETTINGS.CHANNEL_ID is null"));
}
channelCondition.or(specificChannelCondition);
} }
channelCondition.or(specificChannelCondition); sql.and(channelCondition);
} }
sql.and(channelCondition);
return sql; return sql;
} }
......
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