Error: Contents Field on a column layout cannot be a list containing null happens when indexing into a List of Variant?

Certified Lead Developer

I received a pink box error message similar to the following:

Interface Definition: Expression evaluation error at function a!formLayout [line 7]: The contents field on a column layout cannot be a list containing a null. Invalid value at index 1.

I was looking into the interface, and noticed there was an IF() condition that when evaluated to false returned {} instead of say a!textField().  This appeared to be in-line with the error message I was receiving. 

However, I ran into some odd behavior, when I just completely replaced the expression evaluation in the IF() condition with false(), the form layout rendered just fine.

I did some more digging, and I noticed the local variable that was being index'd into was a list of variant, instead of just a straight dictionary.  I dug into it a bit more, and noticed as long as the variable was true dictionary and not a List of Variant, the code works fine.  However, I'm confused to why? The index function had a default value, so if it couldn't find the key/index in the dictionary (as it was searching for the keys/indexes in the list, and the key existed within the element of the list, aka list[1]) it was still returning a default value that should have allowed the conditional to still evaluated.

 

So I'm not blocked, just curious.  I know how to get my code to work, but it seems the error message here is not pointing me to the actual issue.  And if the actual issue is a null value in a list for the contents of a column layout, then why does this happen only when I'm using a list of variant, and not otherwise?

I have included some sample code that highlights this behavior.

First, code that causes Pink Box error:

with(
  local!data: {
    {
      bool: false()
    }
  },
  a!formlayout(
    contents: {
      if(
        index(
          local!data,
          "bool",
          false()
        ),
        a!textfield(
          value: local!data,
          ReadOnly: true
        ),
        {}
      )
    }
  )
)

And now, code that works by simply not having a list of variant:

with(
  local!data: {
    bool: false()
  },
  a!formlayout(
    contents: {
      if(
        index(
          local!data,
          "bool",
          false()
        ),
        a!textfield(
          value: local!data,
          ReadOnly: true
        ),
        {}
      )
    }
  )
)

 

Can any one scratch my curiosity itch?  I mean I know how to get my code to work, but why?  How come the default value for index() being false doesn't get returned and evaluate ok?  It may be super deep under the hood, some weird stack or memory thing, but if you have any ideas, let's discuss!

  Discussion posts and replies are publicly visible