Hi I have written this query to fetch result based on two filter criteria. When I am passing either of employeeId or Created by it throws the following error. But if I pass both employeeId and CreatedBy it works properly. Can anyone help as in what is wrong in this?
The error:
The code:
rule!NGS_queryEntityRefresh( dataStoreEntity: cons!NGS_DSE_QPP_PERFORMANCE_TRACKER, returnType: ri!returnType, executeWhen: ri!executeWhen, queryLogicalExpression: a!queryLogicalExpression( operator: "OR", logicalExpressions: { a!queryLogicalExpression( operator: "AND", filters: { a!queryFilter( field: "employeeId", operator: "in", value: ri!employeeIds, applyWhen: not(rule!NGS_isBlank(ri!employeeIds)) ), a!queryFilter( field: "discussionTopicRefId", operator: "in", value: ri!discussionTopicRefIds, applyWhen: not(rule!NGS_isBlank(ri!employeeIds)) ), a!queryFilter( field: "discussionSubtopicRefId", operator: "in", value: ri!discussionSubtopicRefIds, applyWhen: not(rule!NGS_isBlank(ri!employeeIds)) ), a!queryFilter( field: "date", operator: ">=", value: ri!startDate, applyWhen: not(rule!NGS_isBlank(ri!employeeIds)) ), a!queryFilter( field: "date", operator: "<=", value: ri!endDate, applyWhen: not(rule!NGS_isBlank(ri!employeeIds)) ), a!queryFilter( field: "isActive", operator: "=", value: true, applyWhen: not(rule!NGS_isBlank(ri!employeeIds)) ), a!queryFilter( field: "followUpStatusRefId", operator: "in", value: ri!followUpStatusRefId, applyWhen: not(rule!NGS_isBlank(ri!employeeIds)) ) }, ignoreFiltersWithEmptyValues: true ), a!queryLogicalExpression( operator: "AND", filters: { a!queryFilter( field: "discussionTopicRefId", operator: "in", value: ri!discussionTopicRefIds, applyWhen: not(rule!NGS_isBlank(ri!createdBy)) ), a!queryFilter( field: "discussionSubtopicRefId", operator: "in", value: ri!discussionSubtopicRefIds, applyWhen: not(rule!NGS_isBlank(ri!createdBy)) ), a!queryFilter( field: "date", operator: ">=", value: ri!startDate, applyWhen: not(rule!NGS_isBlank(ri!createdBy)) ), a!queryFilter( field: "date", operator: "<=", value: ri!endDate, applyWhen: not(rule!NGS_isBlank(ri!createdBy)) ), a!queryFilter( field: "isActive", operator: "=", value: true, applyWhen: not(rule!NGS_isBlank(ri!createdBy)) ), a!queryFilter( field: "followUpStatusRefId", operator: "in", value: ri!followUpStatusRefId, applyWhen: not(rule!NGS_isBlank(ri!createdBy)) ), a!queryFilter( field: "createdBy", operator: "in", value: ri!createdBy, applyWhen: not(rule!NGS_isBlank(ri!createdBy)) ) }, ignoreFiltersWithEmptyValues: true ) } ), pagingInfo: ri!pagingInfo, fetchTotalCount: true)
Discussion posts and replies are publicly visible
Did you try simply wrapping each queryLogicalExpression with an if statement instead of putting an applyWhen on every filter?
Looking through the query filters in each branch of the top-level OR clause, I can see there's an even better way to make this far more efficient.
All of the queryFilters between the two main branches are identical except that one of them filters on "employeeId" and the other one filters on "createdBy". Therefore, the top-level QLE should be an "AND", it should contain all 6 of the identical query filters that match between the two, and it should contain a sub-QLE, using "OR", that has the queryFilters for createdBy and for employeeId.