diff --git a/entity/BulkMail_entity/BulkMail_entity.aod b/entity/BulkMail_entity/BulkMail_entity.aod index dbd39ab7d343ce2c8e41f6a40158f69d0bf8ca71..5b41f08661311c31c059f9bfa0243dd3f3a6e84c 100644 --- a/entity/BulkMail_entity/BulkMail_entity.aod +++ b/entity/BulkMail_entity/BulkMail_entity.aod @@ -50,7 +50,6 @@ <onValueChange>%aditoprj%/entity/BulkMail_entity/entityfields/documenttemplate_id/onValueChange.js</onValueChange> <onValueChangeTypes> <element>MASK</element> - <element>PROCESS_SETVALUE</element> </onValueChangeTypes> </entityField> <entityConsumer> diff --git a/entity/BulkMail_entity/entityfields/copybulkmail/onActionProcess.js b/entity/BulkMail_entity/entityfields/copybulkmail/onActionProcess.js index 2a9ba1d3ac294c9ae065823be4c2336480e637d4..7c24cc7374403e24e5204ca5a945d3088da3fbe1 100644 --- a/entity/BulkMail_entity/entityfields/copybulkmail/onActionProcess.js +++ b/entity/BulkMail_entity/entityfields/copybulkmail/onActionProcess.js @@ -2,5 +2,13 @@ import("system.vars"); import("system.neon"); import("Bulkmail_lib"); +// How the copy works: +// - the Bulkmail-context is called in NEW mode and CopyBulkMailId_param set to the current bulkmail id +// - the valueProcess of field BULKMAILID is used to load the data via loadEntity and sets the fields +// (Note: I also could have done it like in offer / order and provide everything as parameter, +// but I tried if i it is possible to do it with less processes and a central process loading the data. +// - The $field.bindata field is set seperately in it's value process +// - The Recipients are added in onDBInsert of the record container + BulkMailUtils.copy(vars.get("$field.BULKMAILID")); \ No newline at end of file diff --git a/entity/BulkMail_entity/grantUpdateProcess.js b/entity/BulkMail_entity/grantUpdateProcess.js index 31a44323d1e0c4301b98c13622b78a8f097bfcbb..25e2b4db25ef91c5f9c3f6b787c757b854993533 100644 --- a/entity/BulkMail_entity/grantUpdateProcess.js +++ b/entity/BulkMail_entity/grantUpdateProcess.js @@ -2,4 +2,4 @@ import("Bulkmail_lib"); import("system.vars"); import("system.result"); -result.object(!BulkMailUtils.isStatusSendingOrSent); \ No newline at end of file +result.object(!BulkMailUtils.isStatusSendingOrSent(vars.get("$field.STATUS"))); \ No newline at end of file diff --git a/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js b/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js index f1f6065954e524d0f637436de4048a9c5e4c4a04..b7a1299898ad76e88e886b8e3b64dff067d125b3 100644 --- a/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js +++ b/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js @@ -1,7 +1,9 @@ +import("system.logging"); import("Sql_lib"); import("DocumentTemplate_lib"); import("system.result"); import("system.vars"); +import("system.entities"); import("system.db"); import("system.util"); import("Document_lib"); @@ -26,7 +28,36 @@ if (template.content) "", template.content, template.filename, "", "", SqlUtils.getBinariesAlias()); } -var contactIds = JSON.parse(vars.getString("$param.PresetRecipients_param")); +var contactIds = []; + +if (vars.get("$param.CopyBulkMailId_param")) +{ + logging.log(JSON.stringify(["COPY: ", + "BulkMailRecipient_entity", + "BulkMailRecipients", + ["BulkMailId_param", vars.get("$param.CopyBulkMailId_param")], + ["#UID"] + +], null, "\t")) + var config = entities.createConfigForLoadingRows() + .entity("BulkMailRecipient_entity") + .provider("BulkMailRecipients") + .addParameter("BulkMailId_param", vars.get("$param.CopyBulkMailId_param")) + .fields(["CONTACT_ID"]); + + var copiedRecipients = entities.getRows(config); + logging.log(JSON.stringify([copiedRecipients], null, "\t")) + + contactIds = copiedRecipients.map(function(pRecipient) + { + return pRecipient["CONTACT_ID"]; + }); +} + +if (vars.getString("$param.PresetRecipients_param")) + contactIds = contactIds.concat(JSON.parse(vars.getString("$param.PresetRecipients_param"))); + +logging.log(JSON.stringify([contactIds], null, "\t")) if (contactIds && contactIds.length > 0) BulkMailUtils.addRecipients(bulkMailId, BulkMailUtils.filterNewRecipients(bulkMailId, contactIds)); \ No newline at end of file