19
Views
13
Comments
List.length returns -1

L.S.,

I needed to know the length of a list. To my surprise .list.length returns a value of -1!

Why would I get this? I can clearly see records when I look at the data from the aggregate.

Kind regards,

Joost

Rank: #151

Hi Joost,

Could you share some images, your flow and the problem occurring during debugging?

this helps us to better understand what may be happening.

Best regards.

Hi Joost,

Good day!

Can you please share a OML?

Kind regards,

Chris

Rank: #1224

Unfortunately I can't share it.

Rank: #510

Hi Joost,

If this problem you are facing is during debugging, It may be related to the OutSystem's query optimization. In summary, to get Length and Count values, separate querys are made by the platform. But, the optimization will only execute them if they were explicitly called in your application. So, if you try to see those values only on the debugger, the result will not be correct, because they weren't executed.

See this link here for more detailed explanation.

Hope it helps.

Best regards.

Rank: #287

Hi Joost,

Is this happen's at debug time or running time?

If it's debug time, then please refer the kadu's answer.

If it's running time please share the oml file.

Kind regards,

Rank: #1224

Hi, 

Yes this is at debugging time. I did set a variable to the value... , but still returns -1.  As far as I can tell from the linked forum entry that should work.

Or maybe I misunderstood. 

Rank: #510

Yes, I think that it should work too.
I don't know how big is the optimization extent, so, do you do anything with this variable or just declare it and set its value? Have you tried to see the value printing it on screen?

Hi Joost,

Wheee do you plan to use the .Length attribute in your logic?

Kind regards,

Chris

Rank: #1224

I just wanted to know the length so I knew the amount of data I am looping thorough. 

OS debugger should just give this stuff to us; we are developers. Inquiring minds need to know!

Lot of room for improvement of the debugger, but that's another thread.

Rank: #510

I have just made a test inside a preparation and both, length and count, was displayed on debugger correctly. To test it, I used an Aggregate.List. Could you share your oml or tell us what are the steps you are doing?

Hi Joost,

Good morning!

Thanks for the info.

How about you run the Log server action then pass the value of the count of the aggregate. I'm thinking that if it your concern still persists regardless of the module, you might be able see it instead in the General logs.

Hope this helps,

Kind regards,

Chris


mvp_badge
MVP
Rank: #71

Hello Joost.

1. Are you using that length anywhere besides the debugger window? Like the answer on that link explains, if the fields are not used, they are not calculated so your "inquiring mind" can't have its answer. Just place an assign or an if after the list creation and the length should show.

2. See if your list has all the records or only current. If all records show, the length is probably available. If you only have one, it means a cursor is in use and probably length wasn't calculated yet. It also bothered me at first, but after a couple of years using lazy evaluation in other languages, I got used to not having some numbers.


PS: And length=-1 means "not calculated" because having "0" would be misleading.

Rank: #510

I execute some tests and this is what I found:

  1. When the aggregate is used as a source for a widget, the Length is calculated;

  2. When the aggregate List.Length is used to set a variable and that variable is used, then the Length is calculated:



  3. When the aggregate List.Length is NOT used anywhere, then the Length is NOT calculated:



  4. When the aggregate List.Length is used to set a variable and that variable is NOT used, then the Length is NOT calculated:


    So, in order to see the Length of an aggregate List, you must used It in your code. Set a variable to its value is not enough, you must use the variable somewhere.

Hope it could help.

Best regards