diff --git a/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod b/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod index 339e6914d5ffe2bea367524f8f684d43cb442d7a..81f16aeb72e4468079d776cff6c8443272e11a48 100644 --- a/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod +++ b/entity/CampaignAddParticipants_entity/CampaignAddParticipants_entity.aod @@ -28,6 +28,7 @@ <element>PROCESS_SETVALUE</element> <element>RECORD</element> </onValueChangeTypes> + <onValidation>%aditoprj%/entity/CampaignAddParticipants_entity/entityfields/campaign_id/onValidation.js</onValidation> </entityField> <entityField> <name>CAMPAIGNSTEP_ID</name> @@ -60,11 +61,6 @@ </entityConsumer> <entityConsumer> <name>CampaignStepConsumer</name> - <dependency> - <name>dependency</name> - <entityName>CampaignStep_entity</entityName> - <fieldName>CampaignSteps</fieldName> - </dependency> <children> <entityParameter> <name>campaignId_param</name> @@ -72,6 +68,11 @@ <expose v="true" /> </entityParameter> </children> + <dependency> + <name>dependency</name> + <entityName>CampaignStep_entity</entityName> + <fieldName>CampaignSteps</fieldName> + </dependency> </entityConsumer> <entityField> <name>UID</name> diff --git a/entity/CampaignAddParticipants_entity/entityfields/campaign_id/onValidation.js b/entity/CampaignAddParticipants_entity/entityfields/campaign_id/onValidation.js new file mode 100644 index 0000000000000000000000000000000000000000..c84027b8fee4b1faaeaa73067205a136f7ce68ba --- /dev/null +++ b/entity/CampaignAddParticipants_entity/entityfields/campaign_id/onValidation.js @@ -0,0 +1,19 @@ +import("system.vars"); +import("system.result"); +import("Sql_lib"); +import("system.translate"); + +let participants = JSON.parse(vars.get("$param.campaignParticipantsRowIds_param")); +if(participants.length > 0) +{ + let thisParticipantCount = newSelect("count('')").from("CAMPAIGNPARTICIPANT") + .where("CAMPAIGNPARTICIPANT.CAMPAIGN_ID", vars.get("$field.CAMPAIGN_ID")) + .and( + "CAMPAIGNPARTICIPANT.CONTACT_ID", + participants, + SqlBuilder.IN() + ).cell(); + + if(parseInt(thisParticipantCount) > 0) + result.string(translate.text("Participant is already participating")); +}