How to properly set up foreach and empty list

I have a list parameter that Comes into my function. This list contains the three separate variables or strings. of those variables I use the string builder to make a complete statement and then I’m trying to assign to another list of the completed statements. I’m starting from an empty list though. I keep getting the error can’ add to null list.

Error Image
image

Solution Image

Values Debug


Yellow highlight is the list i’m trying to use the add to list function on.
Purple highlight is the value i’m using as the souce value for add to ilst.
Parts is of the same type as geminicontentpart

It looks like you’re trying to add to the list in GeminiContent.parts, but the list is null. Initialize the list to an empty list when creating GeminiContent. It looks like this:

solution

The parts property is initialized to (an empty list).

An alternative is to create a separate instance of a list, add to the list, and assign the list to the parts property.

When Linx creates a top level list, it defaults to an empty list. This function will work:

basic

When Linx creates an instance of a custom Type, it defaults to an instance of the type but properties of the type are not initialized. In the below example, Person has a List property called Names. AddToList references Person.Names. Person.Names defaults to null, so this function will not work:

fail

1 Like

Gotcha, Thanks so much! Might help to add a section to the relevant documentation pages mentioning this.