Here is a typical logical expression used within a query rule
a!queryLogicalExpression( operator: "OR", filters: {list of filters here}, ignoreFiltersWithEmptyValues: true ),
to my understanding, the expression above will query the data where either one of the filters is true. But if I changed the operator to AND it will pull the data where all the filters are true. Let's say I now have the following logical expression with nested logical expressions.
a!queryLogicalExpression( operator: "AND", logicalExpressions: { a!queryLogicalExpression( operator: "AND", filters: { a!queryFilter( field: "user", operator: "=", value: value: cons!MY_NAME ), }, ignoreFiltersWithEmptyValues: true ), a!queryLogicalExpression( operator: "AND", filters: { a!queryFilter( field: "name", operator: "=", value: cons!MY_NAME ), }, ignoreFiltersWithEmptyValues: true ) } ),
To my understanding, this is saying query the data from the table where user equals my name, and query the data from the table where the name is my name and then combine them to create the overall query result. However, this doesn't seem to be case. My query returns nothing as if it was saying find the data where the user is my name AND the name is my name. If I switch the first operator to be OR then it returns only one result from the two inner expression rules.
Could someone explain why this is the case? How can I combine multiple expression rules so I can retrieve the data with multiple expression rules for multiple cases and combine them as one?
Discussion posts and replies are publicly visible
Hi Jose H.,
You don't need to use multiple a!queryLogicalExpressions in this case. You can just include an array of Query Filters that you want with the "AND" operator.
a!queryEntity( entity: cons!YOUR_ENTITY, query: a!query( logicalExpression: a!queryLogicalExpression( operator: "AND", filters: { a!queryFilter( field: "status_id", operator: "=", value: cons!STATUS_ONE ), a!queryFilter( field: "name", operator: "=", value: cons!MY_NAME ) } ), pagingInfo: local!pagingInfo ) )
April Schuppel, I know I can do that. My example wasn't clear, I have updated to better show what I meant. In my case the fields name and user would never be the same, but either one can be "my name". So what I was trying to do is pull the data where my name exists on either one of the fields.
In this case it should simply be sufficient to use one queryLogicalExpression() with an OR operator. Nesting logical expression rule calls would then only be needed if you want to stir in additional query parameters to optionally execute at the same time.