Hi,
i m trying to to implement a feature according to which i need to associate specific db records in a list and i need the position of each record in the list to match the id of the db.
I thought that ListInsert would be a good idea to use, as it is suppossingly lets you choose the specific position in the list that you need to insert to.
However, no matter what position i choose the list elements get inserted 0,1,2,3.. etc even though in the iteration that i have i choose to insert them to 1, 4, 5 etc.. (0,2,3 are not supposed to exist)
Is there any way to solve this?
Hi Nikolas,
You have a fundamental misunderstanding of Lists. A List only has the positions 0 through the number of list items. If you have an empty list, it has 0 items, and therefore you can only insert an item at position 0. If the list has one item, there are only positions 0 and 1 available. If the list has two items, there's only positions 0, 1 and 2, and so on.
You are mistaken a list for an array. You cannot have "positions that do not exist" in a list. If you really want that, you must pre-fill the list with empty items (e.g. using ListAppend in a loop), then assign the data to specific list items (indexed by their position).
Hi Kilian, you addressed the matter 100%. I had the exact that misunderstanding and i figured it out on the go yesterday, later on, but i was a bit focused on the progress and didn't update this post!
For the record, i overcomed my issue, by bringing another attribute on my structure and applying a list filter on that attribute.
No problem, glad you found out what was the problem :). Happy coding!
Hello
So what error you get, or it is just inserting it to other indexes, may I know, what happen to other records when you try to insert the elemet to the list.
Also I have created a demo POC on it you can refer here for the solution it might help you -
https://www.outsystems.com/forums/discussion/82719/how-to-use-list-insert-client-action/
ThanksTousif Khan
When i to retrieve an element from the list.. i get an out of bounds error because i am supposed to have an element in position 5 while this in fact is in position 2 !
Alternatively you could create a list of structure like below
Attribute 1 - Database Index (Long Integer)
Attribute 2 - Attribute/Record (Attribute Data Type or Entity Record Type)
In Attribute 1 you can store the database index for the record, and in Attribute 2 you can store the desired attribute of your entity record or entire record if it is not too big and you need all attributes.
Hope it helps!
Junaid
Hi Junaid,
i pretty much followed similar approach and solved it. Thank you very much for your contribution.
Glad to know that!