isNullorEmpty

Hi,

For the above expression rule, if I try to add a!isNullorEmpty(local!ID), then I can getting false, but I am expecting true.

Am I doing anything wrong here.

  Discussion posts and replies are publicly visible

Parents
  • Yes, see below code and screenshot for the difference. It's subtle but technically a list containing all null indexes, even if that's a single index, isn't actually empty. This is good that this happens!

    To get the behavior you want you can either reject all nulls from the list or cast to the scalar (single) integer data type. Both behaviors are demonstrated below.

    a!localVariables(
      local!nullInteger: tointeger(
        null
      ),
      local!listOfNullInteger: cast(
        a!listType(1),
        local!nullInteger
      ),
      local!rejectNulls: reject(
        fn!isnull,
        local!listOfNullInteger
      ),
      local!castToScalarInteger: cast(
        typeof(1),
        local!listOfNullInteger
      ),
      {
        nullInteger: a!isNullOrEmpty(local!nullInteger),
        listOfNullInteger: a!isNullOrEmpty(local!listOfNullInteger),
        rejectNulls: a!isNullOrEmpty(local!rejectNulls),
        castToScalarInteger: a!isNullOrEmpty(local!castToScalarInteger)
      }
    )
     

  • 0
    Certified Lead Developer
    in reply to ajhick

    Try using flatten before a!isnullOrEmpty(). 
    Also, for future use, always create your own null checks. In that, you can loop through the input and check every item for null. This way, you can add all the conditions which should return null in the same rule. 

  • Flatten won't help, if it were flattened it would still contain at least one null element at the end. You should also be careful with the rule you've suggested. It will work of course but you've got to make sure it's the behavior you actually want (Sometimes it is! I've made a rule like this).

    A list of null elements is not empty. Imagine you query for some records and then index to a field and check if it is null or empty. If no records are found then a!isNullOrEmpty() would return true. If records are found but the field indexed to just happens to be null for all the records then a!isNullOrEmpty() should return false (and does) even if the array returned only has one item in the list.

    The main issue the OP is having is the local!opinionDetails variable is returning as a list when it appears as though it will only ever have one element/index in it and so he is expecting Appian to treat it like a scalar data type even though it isn't.

Reply
  • Flatten won't help, if it were flattened it would still contain at least one null element at the end. You should also be careful with the rule you've suggested. It will work of course but you've got to make sure it's the behavior you actually want (Sometimes it is! I've made a rule like this).

    A list of null elements is not empty. Imagine you query for some records and then index to a field and check if it is null or empty. If no records are found then a!isNullOrEmpty() would return true. If records are found but the field indexed to just happens to be null for all the records then a!isNullOrEmpty() should return false (and does) even if the array returned only has one item in the list.

    The main issue the OP is having is the local!opinionDetails variable is returning as a list when it appears as though it will only ever have one element/index in it and so he is expecting Appian to treat it like a scalar data type even though it isn't.

Children
No Data