From 0deddfc3718299c4c538211d08fe2521c608fe5b Mon Sep 17 00:00:00 2001
From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local>
Date: Wed, 29 Jan 2020 11:49:51 +0100
Subject: [PATCH] SerialLetterAddRecipients didn't work

---
 .../entityfields/recipientcontactids/valueProcess.js   | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/entity/SerialLetterAddRecipients_entity/entityfields/recipientcontactids/valueProcess.js b/entity/SerialLetterAddRecipients_entity/entityfields/recipientcontactids/valueProcess.js
index 2c46f4a953..724fccc6b1 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)
 
-- 
GitLab