Skip to main content
November 8, 2021
Solved

how to correctly write the judgement expression for couple of items with null value inside?

  • November 8, 2021
  • 4 replies
  • 0 views

as title, i want express if isnull(backuppricingaudit) then don't do anything with it. Without foreach loop, how to express it?

    Best answer by jordand0005

    Hi immortalvirgil,

    I'm assuming that backuppricingaudit is a local variable you have created in an interface or expression rule?

    If so, one approach you can use is a combination of a!flatten() with isnull() and length().

    By definition a!flatten() converts an array that contains other arrays into an array of single items, preserving the types and relative order of all the nested array items.

    e.g. The following code will return true

    a!localVariables(
      local!backuppricingaudit: { {null}, {null} },
      or(
        isnull(a!flatten(local!backuppricingaudit)),
        length(a!flatten(local!backuppricingaudit)) < 1
      )
    )

    4 replies

    jordand0005
    November 8, 2021

    Hi immortalvirgil,

    I'm assuming that backuppricingaudit is a local variable you have created in an interface or expression rule?

    If so, one approach you can use is a combination of a!flatten() with isnull() and length().

    By definition a!flatten() converts an array that contains other arrays into an array of single items, preserving the types and relative order of all the nested array items.

    e.g. The following code will return true

    a!localVariables(
      local!backuppricingaudit: { {null}, {null} },
      or(
        isnull(a!flatten(local!backuppricingaudit)),
        length(a!flatten(local!backuppricingaudit)) < 1
      )
    )

    November 8, 2021

    length(a!flatten())=0 works

    peter.lewis
    Employee
    November 8, 2021

    This is correct, but I highly recommend that you use both the isnull and length checks. Even if this specific scenario works with checking if length is 0, there are many other scenarios that are triggered if the value is null. Personally the first rule I build (or import as a common object) is a rule for "isNullOrEmpty" that checks both if the value is null OR empty. Spoiler alert - there is also an out-of-the-box function that does both these checks coming in 21.4 [emoticon:c4563cd7d5574777a71c318021cbbcc8]