Skip to content
Snippets Groups Projects
Commit a8261a8c authored by Sebastian Listl's avatar Sebastian Listl :speech_balloon:
Browse files

Merge branch 'm_1074944_copy_campaignparticipants' into '2021.1'

M 1074944 copy campaignparticipants

See merge request xrm/basic!1201
parents 42114f49 6b46c1df
No related branches found
No related tags found
No related merge requests found
......@@ -606,6 +606,13 @@
</entityParameter>
</children>
</entityConsumer>
<entityField>
<name>copyParticipants</name>
<title>Copy Participants</title>
<contentType>BOOLEAN</contentType>
<stateProcess>%aditoprj%/entity/Campaign_entity/entityfields/copyparticipants/stateProcess.js</stateProcess>
<valueProcess>%aditoprj%/entity/Campaign_entity/entityfields/copyparticipants/valueProcess.js</valueProcess>
</entityField>
<entityParameter>
<name>OnlyActive_param</name>
<expose v="true" />
......
import("system.translate");
import("system.vars");
import("Campaign_lib");
var campaignid = vars.get("$field.CAMPAIGNID");
var description = vars.get("$field.DESCRIPTION");
var emplContactId = vars.get("$field.EMPLOYEE_CONTACT_ID");
var name = vars.get("$field.NAME");
var name = vars.get("$field.NAME") +" - " + translate.text("copy");
var state = vars.get("$field.STATUS");
var type = vars.get("$field.TYPE");
var eventType = vars.get("$field.EVENTTYPE");
......
import("system.neon");
import("system.result");
import("system.vars");
if (vars.get("$param.Copy_param"))
{
result.string(neon.COMPONENTSTATE_EDITABLE)
}
else
{
result.string(neon.COMPONENTSTATE_INVISIBLE)
}
\ No newline at end of file
import("system.neon");
import("system.vars");
import("system.result");
if(vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW && vars.get("$param.Copy_param") && vars.get("this.value") == null)
{
result.string("1");
}
\ No newline at end of file
import("Util_lib");
import("Workflow_lib");
import("system.neon");
import("Employee_lib");
......@@ -13,7 +14,13 @@ var rowdata = vars.get("$local.rowdata");
var campaignId = vars.get("$local.uid");
if (vars.get("$param.Copy_param"))
{
CampaignUtils.copyCampaignSteps(JSON.parse(vars.get("$param.Copy_param"))["CAMPAIGNID"], campaignId);
if(Utils.toBoolean(vars.get("$field.copyParticipants")))
{
CampaignUtils.copyCampaignParticipants(JSON.parse(vars.get("$param.Copy_param"))["CAMPAIGNID"], campaignId);
}
}
else
{
var threeWeeks = datetime.ONE_WEEK * 3;
......
......@@ -48,6 +48,10 @@
<name>57992f29-2e55-4f1f-8652-c2817a3b257e</name>
<entityField>EMPLOYEE_CONTACT_ID</entityField>
</entityFieldLink>
<entityFieldLink>
<name>03d28820-8774-4589-bdfe-fa8fa6a8a8ec</name>
<entityField>copyParticipants</entityField>
</entityFieldLink>
<entityFieldLink>
<name>88f13d08-d164-4bac-95fb-713d47ba255b</name>
<entityField>STATUS</entityField>
......
import("system.entities");
import("Util_lib");
import("system.util");
import("system.translate");
......@@ -709,6 +710,8 @@ CampaignUtils.copyCampaign = function(pCampaignid, pDescription, pEmplContactId,
/**
* Copies all campaign steps from one campaign to another.<br>
* Participants will be put into the first campaignstep.<br>
* If it does not have enough room for them the max participants for the first step gets increased.<br>
*
* @param {String} pSourceCampaignId <p>
* The id of the source campaign.<br>
......@@ -727,6 +730,77 @@ CampaignUtils.copyCampaignSteps = function(pSourceCampaignId, pTargetCampaignId)
};
CopyModuleUtils.copyModule(InputMapping);
}
/**
* Copies all campaign participants from one campaign to another.<br>
*
* @param {String} pSourceCampaignId <p>
* The id of the source campaign.<br>
* @param {String} pTargetCampaignId <p>
* The id of the target campaign.<br>
*/
CampaignUtils.copyCampaignParticipants = function(pSourceCampaignId,pTargetCampaignId)
{
var [targetCampaignStepId,targetCampaignStepMaxParticipants] =
newSelect(["CAMPAIGNSTEP.CAMPAIGNSTEPID","CAMPAIGNSTEP.MAXPARTICIPANTS"])
.from("CAMPAIGNSTEP")
.where("CAMPAIGNSTEP.CAMPAIGN_ID",pTargetCampaignId)
.orderBy("SORTING ASC")
.arrayRow();
var participantLoadConfig= entities.createConfigForLoadingRows()
.entity("CampaignParticipant_entity")
.fields(["RESPONSIBLE_CONTACT_ID", "CONTACT_ID"])
.addParameter("CampaignId_param", pSourceCampaignId);
var participants = entities.getRows(participantLoadConfig);
var campaignParticipantsColumns = [
"CAMPAIGNPARTICIPANTID",
"CONTACT_ID",
"CAMPAIGN_ID",
"CAMPAIGNSTEP_ID",
"USER_NEW",
"DATE_NEW"
];
var campaignParticipantLogColumns = CampaignUtils.getParticipantLogInsertColumnNames();
var inserts = [];
participants.forEach(function(participant)
{
var campaignParticipantId = util.getNewUUID();
var campaignParticipantInsertValues = [
campaignParticipantId,
participant["CONTACT_ID"],
pTargetCampaignId,
targetCampaignStepId,
vars.get("$sys.user"),
vars.get("$sys.date")
];
inserts.push(["CAMPAIGNPARTICIPANT",campaignParticipantsColumns,null,campaignParticipantInsertValues]);
var logValues = [
util.getNewUUID(),
pTargetCampaignId,
targetCampaignStepId,
campaignParticipantId,
vars.get("$sys.user"),
vars.get("$sys.date"),
""
];
inserts.push(["CAMPAIGNPARTICIPANTLOG",campaignParticipantLogColumns,null,logValues]);
});
db.inserts(inserts)
if ( targetCampaignStepMaxParticipants && participants.length > Number(targetCampaignStepMaxParticipants))
{
newWhere("CAMPAIGNSTEP.CAMPAIGNSTEPID",targetCampaignStepId)
.updateFields({"MAXPARTICIPANTS":participants.length})
}
}
/**
* Methods for campaignmanagement.<br>
......
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