Skip to main content
March 28, 2022
Solved

logicalExpression within logicalExpression

  • March 28, 2022
  • 4 replies
  • 0 views

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: { #### }

Best answer by stewart.burchell

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
March 28, 2022

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"
      )
    }
  )
)

March 28, 2022

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
March 28, 2022

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"
        )
      }
    )
  }
)