diff --git a/entity/SerialLetterAddRecipients_entity/entityfields/recipientcontactids/valueProcess.js b/entity/SerialLetterAddRecipients_entity/entityfields/recipientcontactids/valueProcess.js index 2c46f4a9539e0e7af98a6bf22b74c2a205b2722e..724fccc6b1b9cd1c8f4c02a78293e71794e3362e 100644 --- a/entity/SerialLetterAddRecipients_entity/entityfields/recipientcontactids/valueProcess.js +++ b/entity/SerialLetterAddRecipients_entity/entityfields/recipientcontactids/valueProcess.js @@ -8,14 +8,14 @@ import("Sql_lib"); import("system.vars"); var contactIds = JSON.parse(vars.getString("$param.ContactIds_param")); -var letterId = vars.get("$field.SERIALLETTER_ID"); - -var existsQuery = "not exists(select LETTERRECIPIENTID from LETTERRECIPIENT where LETTERRECIPIENT.CONTACT_ID = CONTACT.CONTACTID and # = ?)"; contactIds = newSelect("CONTACTID") .from("CONTACT") - .and("CONTACT.CONTACTID", contactIds, SqlBuilder.IN()) - .and("LETTERRECIPIENT.SERIALLETTER_ID", letterId, existsQuery) //only add contacts that aren't already recipients + .where("CONTACT.CONTACTID", contactIds, SqlBuilder.IN()) + .and(null, newSelect("LETTERRECIPIENTID") + .from("LETTERRECIPIENT") + .where("LETTERRECIPIENT.CONTACT_ID = CONTACT.CONTACTID") + .and("LETTERRECIPIENT.SERIALLETTER_ID", "$field.SERIALLETTER_ID"), SqlBuilder.NOT_EXISTS()) //only add contacts that aren't already recipients .and(ContactUtils.getCommRestrictionCondition($KeywordRegistry.communicationMediumCampaign$letter(), true)) //check if there's a commrestriction .array(db.COLUMN)