diff --git a/entity/Campaign_entity/Campaign_entity.aod b/entity/Campaign_entity/Campaign_entity.aod index 9ca492da02dbd6dd4bcaae3e08f20603a17e14a3..9d93c7d23d90afe6e57227857ea04fe64cb86b9e 100644 --- a/entity/Campaign_entity/Campaign_entity.aod +++ b/entity/Campaign_entity/Campaign_entity.aod @@ -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" /> diff --git a/entity/Campaign_entity/entityfields/copycampaign/onActionProcess.js b/entity/Campaign_entity/entityfields/copycampaign/onActionProcess.js index 41c40f28b7e1e859acd3496494af39ed536a1b41..ed3b86c6ff698f6de085ecaddf1457b05416021a 100644 --- a/entity/Campaign_entity/entityfields/copycampaign/onActionProcess.js +++ b/entity/Campaign_entity/entityfields/copycampaign/onActionProcess.js @@ -1,10 +1,11 @@ +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"); diff --git a/entity/Campaign_entity/entityfields/copyparticipants/stateProcess.js b/entity/Campaign_entity/entityfields/copyparticipants/stateProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..4be771bc30514a925d80000647bc20da2970e13f --- /dev/null +++ b/entity/Campaign_entity/entityfields/copyparticipants/stateProcess.js @@ -0,0 +1,12 @@ +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 diff --git a/entity/Campaign_entity/entityfields/copyparticipants/valueProcess.js b/entity/Campaign_entity/entityfields/copyparticipants/valueProcess.js new file mode 100644 index 0000000000000000000000000000000000000000..cf674f4e0072fe0e3a6e9666574498272c91e1a7 --- /dev/null +++ b/entity/Campaign_entity/entityfields/copyparticipants/valueProcess.js @@ -0,0 +1,8 @@ +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 diff --git a/entity/Campaign_entity/recordcontainers/db/onDBInsert.js b/entity/Campaign_entity/recordcontainers/db/onDBInsert.js index ecc62088cac7fd1e7ee7b449554330682ae3a4e2..dbacec7bcd19db949c90e266d712c31531fab609 100644 --- a/entity/Campaign_entity/recordcontainers/db/onDBInsert.js +++ b/entity/Campaign_entity/recordcontainers/db/onDBInsert.js @@ -1,3 +1,4 @@ +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; diff --git a/neonView/CampaignEdit_view/CampaignEdit_view.aod b/neonView/CampaignEdit_view/CampaignEdit_view.aod index 37733b7b887c45f4ce1aec912524e881e38f8ca9..0281a5766d8cccee12732abf5ef1cbf684c28c91 100644 --- a/neonView/CampaignEdit_view/CampaignEdit_view.aod +++ b/neonView/CampaignEdit_view/CampaignEdit_view.aod @@ -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> diff --git a/process/Campaign_lib/process.js b/process/Campaign_lib/process.js index 808c85d412e2b8ed1c67f82693493b11d95cbc1b..aa9f551d99de8e64b391f5cc685801ffc932b480 100644 --- a/process/Campaign_lib/process.js +++ b/process/Campaign_lib/process.js @@ -1,3 +1,4 @@ +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>