Hello developers, i want to remove first and last record from list variable. Is it possible to do it?
Hello,
Like it was said before, the ListRemove action removes a record from the list with a given position.
If the list has N elements, then the first position will be 0 and the last position will be N-1.
Example: list will 10 elements -> [0][1][2][3][5][6][7][8][9]
In order to remove the first position of the list, it is exactly like you did (position 0 of the list).
In order to remove the last position of the list, you can use the length property of the list minus 1. The length property will give you the number of elements currently in the list. If you subtract 1 to this number, then you will have the last position of the list.
In the example above, this is the scenario:
These are the Runtime Properties that you can use in your code for a list:
https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Data/Data_Types/List
Hope it helps.
Kind regards,
Rui Barradas
Rui Barradas wrote: Thank you for your replay Rui, it actually work for me.
Hi,
Use below function to delete record from List,
Also you can refer below link to understand list operation,
And to avoid stupid mistakes: if you remove the first, the last will change position so careful and don't save the position before deleting to then be surprised at not finding it.
Nuno Reis wrote:
If you do in the same call to the server without committing, the last position should be the same, so remove all in the same request, that is right Nuno or am I wrong?
Yes, I agree with Nuno.
Sorry Carlos, I think you're are not correct here.The positions are relative to the elements currently in the List.If you have 10 elements, the last element "position" is 9. If you remove the first element, the last element position is now 8.
Cheers.
P.S. The "effect" is immediate. No related to transaction/request.
Server and commits are not relevant here. This is a local operation.
Removing the later positions first is a good principle, even if there are exceptions (and I can't think of one).
When I remove from a list while in a loop, the object is changed and length changes immediately.
And if a commit was needed, could you alter two elements in one operation? +
Thanks Edu and Nuno for this clarification
Thanks all of you for the fast reply, and i have one more question. As describe in picture, i use the list remove to delete first record as JitendraYadav said. But how can i find the last position of last record?
No problem mate, I'm glad that you managed to do it.