diff --git a/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js b/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js index fb39eed20e0040a1f60fb9c63c93fa050d32fc18..471416a0f8668d62254f1bcdb2f73c652b8925af 100644 --- a/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js +++ b/entity/CampaignAddParticipants_entity/entityfields/isoperationvalid/valueProcess.js @@ -68,9 +68,17 @@ if(selectedCampaignId != '') else { participantCondition = JSON.parse(vars.getString("$param.campaignParticipantsCondition_param")).condition; - - countParticipantsToAdd = CampaignUtils.GetContactCountByCondition(participantCondition); - + logging.log("im isOperationValid -> "); + countParticipantsToAdd = CampaignUtils.GetContactCountByCondition(participantCondition, isUpdate); + logging.log("countParticipantsToAdd -> " + countParticipantsToAdd); + + /* + * If the update mode is active, the goal is to move participants between steps. + * therefore the check if the affected participants already are added to a particluar step has to be on the step level. + * + * If not, participants are to be added. It has to be checked if a participant is in a campaign, regardless of the particular + * step because one participant can be in a campaign just once. + */ if(isUpdate == "true") whereCondition = "CAMPAIGNPARTICIPANT.CAMPAIGNSTEP_ID = '" + selectedCampaignStepId + "'"; else diff --git a/entity/Organisation_entity/Organisation_entity.aod b/entity/Organisation_entity/Organisation_entity.aod index ac2e0d37071ad4bf7f8e7fbc673939e097702481..4ea751da8055b487586369cff0c75f24469b05e3 100644 --- a/entity/Organisation_entity/Organisation_entity.aod +++ b/entity/Organisation_entity/Organisation_entity.aod @@ -774,7 +774,7 @@ <title>Add to Campaign</title> <onActionProcess>%aditoprj%/entity/Organisation_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js</onActionProcess> <isObjectAction v="false" /> - <isSelectionAction v="true" /> + <isSelectionAction v="false" /> <iconId>NEON:GROUP_APPOINTMENT</iconId> <tooltip>Add the selection to a campaign</tooltip> <tooltipProcess>%aditoprj%/entity/Organisation_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/tooltipProcess.js</tooltipProcess> diff --git a/entity/Organisation_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js b/entity/Organisation_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js index 8ae8d45bb07577457f0511bdb492322be2b7cd6a..c9b89f86a88ad0145a75d7a744938b719fca4c3e 100644 --- a/entity/Organisation_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js +++ b/entity/Organisation_entity/entityfields/campaignactiongroup/children/addtocampaignfromtable/onActionProcess.js @@ -2,14 +2,20 @@ import("system.vars"); import("system.neon"); import("Campaign_lib"); -var sysSelection = vars.getString("sys.selection"); +var sysSelection = vars.get("$sys.selection"); +/* + * If there's a selection only those are ought to be added. + * Otherwise the filter gets checked, if a filter has beed set, the condition + * is used to determine the objects to be added. + * If no selection has been set, all objects will be added. + */ if(sysSelection.length > 0) //selektierte IDs als Array { - CampaignUtils.addParticipantsByRowIds(sysSelection, "ORGANISATION"); + CampaignUtils.addParticipantsByRowIds(JSON.stringify(sysSelection), "ORGANISATION"); } else { let sysFilter = vars.get("$sys.filter");//todo change name - CampaignUtils.addParticipantsByCondition(sysFilter.condition, "ORGANISATION"); + CampaignUtils.addParticipantsByCondition(JSON.stringify(sysFilter), "ORGANISATION"); } \ No newline at end of file diff --git a/process/Campaign_lib/process.js b/process/Campaign_lib/process.js index 9fc534013e2ee915ed7cef03af48d1bc0b837f99..e16e5b948a2e8d13f493eb624f29940f510e8580 100644 --- a/process/Campaign_lib/process.js +++ b/process/Campaign_lib/process.js @@ -343,8 +343,10 @@ CampaignUtils.GetParticipantsAlreadyAddedCountByCondition = function(pWhereCondi + " left join ADDRESS on (ADDRESS.ADDRESSID = CONTACT.ADDRESS_ID)" + " left join CAMPAIGNPARTICIPANT on CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID" + " where " + pWhereCondition - + " and " + pCondition; + if(pCondition != "") + query += " and " + pCondition; + logging.log("GetParticipantsAlreadyAddedCountByCondition query -> " + query); return db.cell(query) @@ -369,11 +371,13 @@ CampaignUtils.GetContactIdsNotInCampaignByCondition = function(pCampaignId, pCon + " 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 " + pCondition - + " and CONTACT.CONTACTID not in" + + " where CONTACT.CONTACTID not in" + " (select CAMPAIGNPARTICIPANT.CONTACT_ID from CAMPAIGNPARTICIPANT where" + " CAMPAIGNPARTICIPANT.CAMPAIGN_ID = '" + pCampaignId + "')"; + if(pCondition != "") + query += " and " + pCondition; + return db.array(db.COLUMN, query); } @@ -390,13 +394,15 @@ CampaignUtils.GetContactIdsInCampaignByCondition = function(pCampaignId, pCondit return db.array(db.COLUMN, query); } -CampaignUtils.GetContactCountByCondition = function(pCondition) +CampaignUtils.GetContactCountByCondition = function(pCondition, pLookInCampaignOnly) { let query = "select count(*) 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)" - + " left join CAMPAIGNPARTICIPANT on CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID"; + + if(pLookInCampaignOnly == "true") + query += " left join CAMPAIGNPARTICIPANT on CAMPAIGNPARTICIPANT.CONTACT_ID = CONTACT.CONTACTID"; if(pCondition != "") query += " where " + pCondition;