Empty resultset evaluation

Hi,

I am new to Appian and in learning phase. I would like to know how do I treat empty resultSets while using using a!forEach  combined with a!queryEntity

My requirements:

  1. Query a table
  2. When there are no results, return false 
  3. If there are results, iterate the results and return if the result set contains non blank items of a column

I had added an if condition in a!forEach expression. I am using fv!itemCount>0 condition which works fine only when there are valid results. it is not going into the false block when the resultset is emtpy.

How do i check a!queryEntity returns an empty entity/ data without any results?

Your help is much appreciated!

Please ignore any typos/syntax errors on the below snippet. 

load(
local!localCollections: a!queryEntity(
entity: cons!MY_ENTITY,
query: a!query(
logicalExpression: a!queryLogicalExpression(
operator: "AND",
filters: {
a!queryFilter(
field: "myPK",
operator: "=",
value:6
),
ignoreFiltersWithEmptyValues: true
),
pagingInfo:a!pagingInfo(startIndex: 1, batchSize: - 1
)
),
fetchTotalCount: true

),
a!forEach(
items:local!localCollections,
expression : if(fv!itemCount>0,
rule!GBL_isNotBlank(index(fv!item, "status", null)),
true()
)
)
)

  Discussion posts and replies are publicly visible

Parents
  • Hi There,

    You could try to add the following filter, that would help you to remove the null values:

              a!queryFilter(
                applyWhen: not(rule!GBL_isNotBlank(ri!NO_BLANK_COLUMN)),
                field: "NO_BLANK_COLUMN",
                operator: "not null",
                value: ri!NO_BLANK_COLUMN
              ),

    Hope that helps,

    Regards,

    Acacio B.

  • Acacio,

    Many thanks for your time. I figured out  after i posted and I have already added the operator not null in operator. The problem is when the user searches for a where clause, chances are it may not match any results and will return no results. 

    May I know how do I  find out if the items i use in a!forEach is a valid list and not a {}.  

    i had used fv!itemCount in expression of a!forEach. In the below snippt, itreturns true when the itemCount>0, but not returning false when the itemCount =0

    a!forEach(
    items:local!localCollections,
    expression : if(fv!itemCount>0,
    rule!GBL_isNotBlank(index(fv!item, "status", null)),
    false())

    any directions/pointers would be very helpful 

  • Hi Kumar, 

    What is the current value that you have in your local!localCollections?

    If I understood correctly your scenario even after apply the "Not Null" filter you still have null entries in your return?

    I'm not sure why you would need the foreach, perhaps you could use reject().

    Is your final goal to have a list of Booleans? Or the values that where found in the query?

    Sorry if I got confuse here Slight smile

  • Hi ,

    The query entity will usually return the results in a data subset type. I could see that you're typically giving the data subset as the input to the forEach(). The function has the ability to operate on the data inside the data subset & if it has no data, then the function will not even call the expression defined. Hence you might not be getting the output.

    Below code snippet might help you to return false if there are no data(this is one way, there are other ways too).

    a!localVariables(
      local!localCollections: a!queryEntity(
        entity: cons!MY_ENTITY,
        query: a!query(
          logicalExpression: a!queryLogicalExpression(
            operator: "AND",
            filters: {
              a!queryFilter(
                field: "myPK",
                operator: "=",
                value:6
                )
            },
            ignoreFiltersWithEmptyValues: true
          ),
          pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 10)
        ),
        fetchTotalCount: true
      ),
      if(
        index(local!localCollections, "totalCount", 0) = 0,
        false(),
        a!forEach(
          items: local!localCollections,
          expression: if(
            fv!itemCount > 0,
            rule!GBL_isNotBlank(index(fv!item, "status", null)),
            true()
          )
        )
      )
    )

     But I'm still not getting your specific use case - whether it is to return a boolean array (or) list of items that are not null?

  • Final goal is to return the list of booleans . I forgot the and in the code snippet.

    Objective is to return false when there are no records returned and return true/false if there are records and one of the column is non-blank.

    The solution given by is what i am looking for

    index(local!localCollections, "totalCount", 0) = 0

    Thank you so much for your time and help. Much appreciated

  • Thanks, this is exactly is what i am looking for.

    Thank you for your time and help. Much appreciated.

Reply Children
No Data