From dee0d8a7575684672b4eb577ebc22a9b0dce2d2d Mon Sep 17 00:00:00 2001
From: "j.goderbauer" <j.goderbauer@adito.de>
Date: Wed, 13 Nov 2019 08:07:41 +0100
Subject: [PATCH] [Projekt: Entwicklung - Pool][TicketNr.: 1047128][Filter von
 Kontakt auf Firmenfelder funkioniert nicht] # Conflicts: #
 entity/Person_entity/recordcontainers/db/recordfieldmappings/organisations/filterConditionProcess.js

---
 .../organisations/filterConditionProcess.js           | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/entity/Person_entity/recordcontainers/db/recordfieldmappings/organisations/filterConditionProcess.js b/entity/Person_entity/recordcontainers/db/recordfieldmappings/organisations/filterConditionProcess.js
index b2c8e025af0..58155b84d17 100644
--- a/entity/Person_entity/recordcontainers/db/recordfieldmappings/organisations/filterConditionProcess.js
+++ b/entity/Person_entity/recordcontainers/db/recordfieldmappings/organisations/filterConditionProcess.js
@@ -1,10 +1,9 @@
 import("system.vars");
 import("system.result");
 
-var sqlStr = "select PERSON_ID from CONTACT where ORGANISATION_ID in " +
-    " (select CONTACT.ORGANISATION_ID from CONTACT " +
-    " join ORGANISATION on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID) " +
-    " where PERSON_ID is null and " + vars.get("$local.condition") + ")" +
-    " and PERSON_ID is not null";
+//it's necessary to join the organistion-contact since you may want to search for things like status, language, etc. from an organisation
+var from = "CONTACT PersonContact\n\
+    join ORGANISATION on (ORGANISATION.ORGANISATIONID = PersonContact.ORGANISATION_ID)\n\
+    join CONTACT on (ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID and CONTACT.PERSON_ID is null)";
 
-result.string("PERSONID in (" + sqlStr + ")");
\ No newline at end of file
+result.string("PERSONID in (select PersonContact.PERSON_ID from " + from + " where " + vars.get("$local.condition")+ ")");
\ No newline at end of file
-- 
GitLab