Skip to main content
sivanagamalleswarit0001
Inspiring
May 5, 2023
Question

How to return true value for null list of records

  • May 5, 2023
  • 6 replies
  • 0 views

I just want to understand why list of records(0 items) is not returning null/true in below scenarios.

I have problem returning the List of Empty Records to be empty/null.

Any thoughts??

We always practiced using null vs 0 vs "" vs {} depending on the type of data. However here {} for set of array records is not working to identify as null. Of course same behavior with CDT's as well.

    6 replies

    May 5, 2023

    This is the known behaviour of a!isnull() and a!isnullOrEmpty() also, as it probably uses length() function to check if a value is null which would return 1 for a null CDT or record. You can consider it as a best practice to use the below code to check null values for CDTs and Records specially.

    {
      a!isNullOrEmpty({}),
      cast(type!Map,{}) = a!map(),
      cast('recordType!{aa4ce38f-1a9d-4827-af51-e2ccb80a2c8b}AS Vehicle',{}) = ri!value,
      cast(type!{urn:com:appian:types:PA}PA_AA_VEHICLE,{}) = ri!cdt
    }

    sivanagamalleswarit0001
    Inspiring
    May 8, 2023

    Thank you for your response Sanchit

    mikes0011
    Brainy
    May 5, 2023

    The primitive isnull() function is a bit finnicky with respect to what it considers "null" - in Appian, arrays are a totally different data type from single values, and an empty array has never technically counted as null according to isnull().  In older days we were encouraged to set up a separate expression rule like "rule!apn_isBlank()" which would do a more robust test for null / blank / empty, returning a more intiutive return when fed (for example) an empty list of query result, or other sorts of potentially-empty values.  These days however, we have a!isNullOrEmpty() which accomplishes at least (i'll estimate) 80 - 90% of the corner-case handling that we formerly needed to use a specialty expression rule for (there remains a particular corner case, which I don't remember off the top of my head).

    The Expression Guru
    sivanagamalleswarit0001
    Inspiring
    May 8, 2023

    Thank you Mike, 

    I tried this to fix my problem and worked!!

    = or(
    ri!singlePV = "",
    isnull(ri!singlePV),
    a!isNullOrEmpty(ri!singlePV)
    )

    stefanhelzle0001
    Brainy
    May 6, 2023

    I recently wrote a blog post about NULL checks. You find it here: appian.rocks/.../

    sivanagamalleswarit0001
    Inspiring
    May 8, 2023

    Thanks Stefan, this is very informative!!

    all(a!isNullOrEmpty(_), a!flatten(ri!value)) --> this worked too!