Difficulty creating nested list in codeless

Hello!

Right now I’m trying to create a nested list in Codeless and I’m having some difficulties.
In the snippet below, I’m creating a list called serviceEntry, which should be an array consisting of three objects. I am also creating another list called serviceLineList, which consists of one or more of the serviceEntry list.

Upon inspection of the console, serviceEntry and serviceLineList look identical. serviceEntry looks as expected, an array of three objects. However, I expect serviceLineList to have a length of one, consisting of a single array of three objects. Instead, I also see an array of three objects.

image

I am unsure of why this is the case and can’t seem to find similar cases. Any help would be appreciated!

Hello, @braxton_kinney.

You can do it like this:

Regards, Nikita.

This is more or less what’s already happening in the image I linked above. Changing the codeless around to be more syntactically similar to what you’ve provided I get the same results -

Here the serviceLineList is being instantiated as an empty list
image

Here the serviceEntry list is being created with three objects, then appended to serviceLineList

Here is the result, instead of serviceLineList being an array of length 1 consisting on array, it’s still identical to serviceEntry, a list containing 3 items.
image

You just need to use logic that I sent to you nearly.
Full example:

Here my result:
image

This is exactly the result you want to achieve.
You need to use ‘set’ for this. Because ‘add’ method concatenate the elements of first array to second.

This doesn’t apply in my case since serviceLineList, the list of lists, exists within a for loop. It will have multiple serviceEntry lists appended to it, if we use ‘set’ instead of ‘add’, it will be re-instantiated each iteration of the loop

Ok, I understand give me a time. I will get back with answer ASAP.

Regards, Nikita,

I found a way to do this!

I ended up creating a custom code component, I didn’t realize that ‘add’ would concatenate, so I wrote this which works

image

Excellent!
I’ll see if it can be done without custom code and let you know. But this is a great workaround

1 Like