Query entity with multiple logical expressions

A Score Level 2

Is it possible to have a query entity with multiple logical expressions? i.e. have a query entity that has a logical expression that 'AND's a set of filters and another logical expression that 'OR's a set of filters and 'AND's those two logical expressions together. Any info is greatly appreciated

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    Hi,

    It is possible. In this case, it should satisfy both logical expressions. All filters should be true in AND logical expression and any one of the filters should be true in OR logical expression.

    Please have a look in the code:

    a!queryEntity(
    entity: cons!PG_ENTITY_EMPLOYEE_DETAILS,
    query: a!query(
    logicalExpression: a!queryLogicalExpression(
    operator: "AND",
    logicalExpressions: {
    a!queryLogicalExpression(
    operator: "AND",
    filters: {
    a!queryFilter(
    field: "RequestId",
    operator: "=",
    value: ri!requestId
    )
    }
    ),
    a!queryLogicalExpression(
    operator: "OR",
    filters: {
    a!queryFilter(
    field: "Status",
    operator: "=",
    value: ri!status
    ),
    a!queryFilter(
    field: "IsActive",
    operator: "=",
    value: ri!isActive
    )
    }
    )
    }
    ),
    pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: - 1
    )
    )
    )

  • 0
    Certified Lead Developer

    To perhaps put it more simply, a!queryLogicalExpression() has the logicalExpressions: parameter specifically for this reason.  So you can make basically any combination of nested entries as needed.  If your top logical expression uses an "AND" operator, then it will return results that match all entries in the "filters" parameter as well as within the "logicalExpressions" parameter - so here you could potentially have a nested logical expression that uses the "OR" operator.