Skip to main content
erazemk6135
March 22, 2024
Solved

query filter not working as expected

  • March 22, 2024
  • 11 replies
  • 0 views

I have this code which I use to query task report. I want the filter to check if the asignee groups are in an array of input groups. Take a look at the working example first:

a!queryProcessAnalytics(
    report: cons!GBD_Report,
    contextProcessModels: cons!GBD_Process,                                      
    query: a!query(
      pagingInfo: a!pagingInfo(
        startIndex: 1,
        batchSize: 100,
      sort: a!sortInfo(                                          
        field: "c2",                                             
        ascending: true                                          
        ),    
      ),
    filter: a!queryFilter(
        field: "c4",
        operator: "=",
        value: ri!group
      )
    ),
  ),

This works because ri!group is not an array but a single group. However when I turn the ri!group into an array of groups, and instead of operator "=" use operator "in" so basically check if group is IN an array of groups I get no data. If I use "not in" operator I get the opposite - I get all tasks. What is the issue here?

    Best answer by davidj137213

    Use or operator instead of AND (more than one queryLogicalExpression can be used in logicalExpressions)

    a!queryLogicalExpression(
    operator: "OR",
    filters: {
    a!forEach(items: ri!group,
    expression:
    a!queryFilter(
    field: "c4",
    operator: "=",
    value: fv!item,
    applyWhen: a!isNotNullOrEmpty(reject(fn!isnull, ri!group))
    ),
    )}),

    11 replies

    davidj137213
    Brainy
    March 22, 2024

    Do it this way


    a!forEach(items: ri!group,
    expression:
    a!queryFilter(
    field: "c4",
    operator: "=",
    value: fv!item,
    applyWhen: a!isNotNullOrEmpty(reject(fn!isnull, ri!group))
    ),
    )

    erazemk6135
    March 22, 2024

    But this applies all filters at once right? This means the resulting tasks will have to be in the both groups? I want to return tasks that match any group. So like an union.

    Also when I test this it only works for the first group in the array.
    When I put only group A as input I get 14 tasks.
    When I put group B as input I get 4 tasks.
    When I put {A, B} I get 14 tasks.
    When I put {B, A} I get 4 tasks.

    What is going on here?

    davidj137213
    Brainy
    March 22, 2024

    Use or operator instead of AND (more than one queryLogicalExpression can be used in logicalExpressions)

    a!queryLogicalExpression(
    operator: "OR",
    filters: {
    a!forEach(items: ri!group,
    expression:
    a!queryFilter(
    field: "c4",
    operator: "=",
    value: fv!item,
    applyWhen: a!isNotNullOrEmpty(reject(fn!isnull, ri!group))
    ),
    )}),