297
Views
14
Comments
Solved
Index out of Bounds
Application Type
Mobile
Service Studio Version
11.53.42 (Build 62025)

Hey,

I know there are already a lot of questions regarding this topic, but unfortunately none of them seem to help me.

So here my newbie index question:

1) I have an aggregate that gets me 5 rows. 

2) On a screen I want to show one record of these rows

3) Using the standard procedures (dragging the fields on the screen) I get for the fields the "Aggregate.List.Current.Struct.XXX" definition for each attribute.  Works fine, it shows me, when the app is running, the first entry of the list

4) Now I want to see the some specific element on the list. So I hardcode "Aggregate.List[2].Struct.XXX". But this leads to the exception.

To check where I am wrong I added the following expressions to my screen:

GetIOStepsByInspectionOrderId.Count --> Result 5

GetIOStepsByInspectionOrderId.List.Current.IOStep.Description --> Gives me the first entry

GetIOStepsByInspectionOrderId.List[1].IOStep.Description --> When added, fails as well

Do I misspell something? Or did not understand a concept of outsystems?

Oliver

2024-12-10 04-40-04
Gitansh Anand
Solution

Hi Oliver Flöricke, I tried to replicate the issue and found the reason. This is happening because the screen starts to render before the data is fetched, and the list is empty at that moment, which leads to the problem at hand.
I tried a few things, like wrapping the expression in a container and chaining the container's visibility to the IsDataFetched property of the aggregate, but it did not work.

So here is the solution that did work: set the value of the expression like this:

If(GetIOStepsByInspectionOrderId.IsDataFetched, GetIOStepsByInspectionOrderId.List[1].IOStep.Description,"")

Thanks
Gitansh Anand

UserImage.jpg
Oliver Flöricke

Thank you very much! That indeed did the trick!


2024-03-08 07-04-05
Frederico Capitão

Hello Oliver,

The terminology is correct.

Aggregate.List[Row].Entity.Attribute


Are you able to share a screenshot of the exact error message and where are you trying to show/see that value? Or even better an example oml with your case?

Fred

UserImage.jpg
Oliver Flöricke

Hi Fred,

thank you very much for your reply!

This is the error msg:

This is the layout of my test screen:

I've marked the expression that fails

This is how I have defined it:
When I use it, it fails.

The expression on the left works:

It shows the "Description" of the first row when running, same goes for the "Count" above - it shows "5". Only if I add the erroneous (?) "List[1]" expression it fails.

Does this help?

Oliver

2024-03-08 07-04-05
Frederico Capitão

Hello Oliver,

Are you sure your aggregate is being fetched on start rather than on-demand?

If you put an expression with the length, does it return anything?

UserImage.jpg
Oliver Flöricke

Hi Frederico,

yes, it gets data - because when I use "..Current" I see the elements of the first record so there has to be data (at least from my understanding)

But what exactly do you mean by "put an expression with the length"?

Oliver

2024-03-08 07-04-05
Frederico Capitão


Hello Oliver,

Assign the length of the aggregate to a a widget expression on the screen.
Do you have the max records property set on the aggregate?

Fred

UserImage.jpg
Oliver Flöricke


Ah, sorry I didn't understood that you mean it that way. Yes - I already assigned the length to a widget expression. This is how I know that the aggregate contains the correct number of elements (5).

And max record attribute is set to "MaxRecords" (and the Fetch At start is also set)

Oliver

2024-03-08 07-04-05
Frederico Capitão

Can you not copy that screen on to a example oml and share it here?

UserImage.jpg
Oliver Flöricke

This is the oml of my project. It may look a little bit confusing since this is my very first try with outsystems...

The screen is "IOStepDetail" - it gets from "IOSteps" an orderID to select a list of steps. This created the aggregate we talk about here: GetIOStepsByInspectionOrderID"

Thanks in advance for your effort!
Oliver

CheckVehicle.oml
2024-03-08 07-04-05
Frederico Capitão

Hello Oliver,

I believe you are getting this error message because the aggregate hasn't finished fetching the data, but you are already trying to display it on screen.

To avoid such error, you can wrap the expression around an if widget validating if the aggreagate has already fetched all the data.

Have a look as well at this documentation regarding the screens and blocks lifecycle: https://success.outsystems.com/documentation/11/developing_an_application/implement_application_logic/screen_and_block_lifecycle_events/

Hope it helps,
Fred

2018-10-29 08-31-03
João Marques
 
MVP

Hi Oliver,


You should use the length instead of the count, to see the number of elements in a list.

It's also a good practice to check first before trying to access a specific element, if the list has those many elements.

For instance, if(MyAggregate.List.Length >= 2, MyAggregate.List[1].Structure.Value, 0)


And last, but not least, the index is zero-based. Meaning that your first element is in the 0 position, the second is in the 1, and so on.


Kind Regards,
João

UserImage.jpg
Oliver Flöricke

Hello Joao,

Thank you for your answer.

And yes, in general I would check any boundaries. But for this test case I know I have 5 elements in the list and I simply want to learn how to address the individual elements of a list. :-)

And: Changing from "Count" to  "Length" leaves me again with "5" - is this a coincidence?

Oliver

2023-04-16 15-25-31
Krishnanand Pathak

Hi Oliver,

You just need to enclose the expression inside if widget with the condition like (GetUsers.IsDataFetched) as shown below.


It will work fine. The issue is with loading complete list from aggregate.
Use IsDataFetched property in the if widget condition to prevent this exception.
OML is also attached for better understanding.

Regards
Krishnanand Pathak

PrintListItem.oml
2024-12-10 04-40-04
Gitansh Anand
Solution

Hi Oliver Flöricke, I tried to replicate the issue and found the reason. This is happening because the screen starts to render before the data is fetched, and the list is empty at that moment, which leads to the problem at hand.
I tried a few things, like wrapping the expression in a container and chaining the container's visibility to the IsDataFetched property of the aggregate, but it did not work.

So here is the solution that did work: set the value of the expression like this:

If(GetIOStepsByInspectionOrderId.IsDataFetched, GetIOStepsByInspectionOrderId.List[1].IOStep.Description,"")

Thanks
Gitansh Anand

UserImage.jpg
Oliver Flöricke

Thank you very much! That indeed did the trick!


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.