Skip to main content
New Participant
Mar 28, 2022 8:39 AM UTC
Solved

logicalExpression within logicalExpression

Hi!

I'm trying to put logicalExpression within logicalExpression ( one of them will be with operator "AND" and the other one "OR")

and I dont know how to write it.

Where should I put the logicalExpression with the "AND" operator? for simplify it the "AND" contains the "OR".

local!dataSubset: a!queryEntity_18r3(
entity: #######,
query: a!query(
pagingInfo: a!pagingInfo(1,-1),
logicalExpression: a!queryLogicalExpression(
operator: "OR",
filters: { #### }

stewart.burchell
Employee
Mar 28, 2022 8:55 AM UTC

You can use the logicalExpressions attribute (note the plural) - this can take an array:

a!queryEntity(
  query: a!queryLogicalExpression(
    logicalexpressions: {
      a!queryLogicalExpression(
        operator: "AND"
      ),
      a!queryLogicalExpression(
        operator: "OR"
      )
    }
  )
)

4 replies

stewart.burchell
Employee
Mar 28, 2022 8:55 AM UTC

You can use the logicalExpressions attribute (note the plural) - this can take an array:

a!queryEntity(
  query: a!queryLogicalExpression(
    logicalexpressions: {
      a!queryLogicalExpression(
        operator: "AND"
      ),
      a!queryLogicalExpression(
        operator: "OR"
      )
    }
  )
)

New Participant
Mar 28, 2022 9:21 AM UTC

Hi,

Thank you for the quick response! 

I did not understand how this query represent logicalExpression within logicalExpression.

I meant that the logicalExpression "OR" will be inside the logicalExpression "AND".

Could you verify? 

peter.lewis
Employee
Mar 28, 2022 7:03 PM UTC

Stewart didn't specifically add the AND operator at the top level, but that's essentially what's happening in his example. Here's an example with some more filters so you can see how it works:

a!queryLogicalExpression(
  operator: "AND",
  logicalexpressions: {
    a!queryLogicalExpression(
      operator: "AND",
      filters: {
        a!queryFilter(
          field: "isActive",
          operator: "=",
          value: true
        ),
        a!queryFilter(
          field: "status",
          operator: "<>",
          value: "Complete"
        )
      }
    ),
    a!queryLogicalExpression(
      operator: "OR",
      filters: {
        a!queryFilter(
          field: "type",
          operator: "=",
          value: "Top"
        ),
        a!queryFilter(
          field: "region",
          operator: "=",
          value: "West"
        )
      }
    )
  }
)