Good day guys,I keep getting error Index out of bounds index 0 for empty list.
I have run a query for my database and as expected the values that may run will be dynamic. I have run the advance sql query successfully and can plot the generated structure on a table widget.
However when i try to point the necessary value for an expression using MySqlDatarun.GeneratedList[0].Name it throws the error for index out of bounds.The data action is within my screen.Note: The generated structure can be viewed from a table widgetWhat i want to do is i need to put the values on an expression using list indexes and assign each record to an expression. i can assign the values 1 by 1 on a variable but my screen will be populated with too many variables/parameters that's why i come up with a new approach.
Hi,
It happens because there is a race condition between browser loading the page and the data action that is running. Sometimes u got the page correct (may be for the first try, and error if u try again or refresh it), or it succeed when u use new incognito window, those are the symptoms.
To solve it, try put this condition:
If(DataAction1.IsDataFetched,DataAction1.UserList[1].Name,"")
with the semantic like this:
"Hi browser engine, please defer to render this part until dataaction is finished :)"
May this helps
Hi Kert
from what I understood from what you wrote, an empty list has no index, it is empty that's it. I think before accessing the list you should test it to see if it's empty or not.
Regards
Hi Kert,
Apart from the error, which is difficult to tell the cause of since your description is difficult to follow, you may have a more severe problem in that you are trying to do something in a way that's not best practice.
A query returns 0 or more records, which have identical structure. With an SQL, you need to define the Structure explicitly (unless you return full database entity records), and map the right attributes via the SELECT (so there are no structures "generated" as you wrote). It is very uncommon for query's to always return the same data, in a way that index 0 or index 1 is always a specific kind of data you're after (unless you are querying a static entity you have full control over).
So I really don't understand why you want to use specific indexed records in an expression. What kind of expression is this? Can you share some more information on what you are trying to do?
Apologies for the confusions but let me explain it further.Hope that you can help me with this.This is my sample dataThis is just 4 entries but originally im working on thousands of rows and a bit much of columnsIm running an SQL action to parse the data base on "Category" = Games so i have run a data action for sql and i have resulted to:
In this test, it shows that the sql query runs correctly since I got the data that i needed, now its time to put those values (Targetname, lowval1, highval1, lowval2,highval2) in the frontend.In this frontend, it results that the structure from the sql has been generated (table test) so there is something to begin with.
Now i have tested the values if it possible to put it in a expression "Games field",on the first expression widget, i have used "DataAction1.Out1.Current.Targetname" that's why it shows the value "Target1" which is the value from the 1st row of the generated list. Same code has been used for "0" and "5" values.
Info:Out1 (output parameter is set to SQLList List)
Now my goal is to get the value of the second row from that structure to put in the second expression widget, which is named "Value 2" on the pic.
When I use the code "DataAction1.Out1[1].Targetname" to get the Targetname from 2nd row The error showed for Index out of bounds index 1 for empty list.
Sorry if i have used a test samples for this query. Due to confidential and sensitive information, we are not allowed to post the data in public. Anyhow, this is the same use-case. In this scenario, we are just working for 1 category but honestly I am working with more or less than 10 categories with hundreds of rows per category , that's why i would like to come up with a new approach.
"It happens because there is a race condition between browser loading the page and the data action that is running. "I guest this would be the cause of the error , because running the test on the original data, it luckily showed the values, but whenever I refreshed the frontend for the new condition, it comes up with the error. Tested the new approach and it works. Thanks ibox!What i have done:1. created a variable for dynamic filter on the sql query to make the fronted change in any condition2. put the condition on the expression widget: If(DataAction1.IsDataFetched,DataAction1.UserList[1].Name,"") 3. tested changing the values by switching screens and it works like a charm.
Thank you so much! you saved my module from million of variables!