51
Views
11
Comments
Solved
Remove first and last record
Question

Hello developers, i want to remove first and last record from list variable. Is it possible to do it?

Rank: #157
Solution

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:

  • List with 10 elements -> remove first: position 0 -> list with 9 elements
  • List with 9 elements -> remove last: position lenght - 1 -> list with 8 elements


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

mvp_badge
MVP
Rank: #129

Hi,


Use below function to delete record from List,


Also you can refer below link to understand list operation,

https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Data/Data_Types/List

mvp_badge
MVP
Rank: #69

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.


mvp_badge
MVP
Rank: #129

Yes, I agree with Nuno.

mvp_badge
MVP
Rank: #5

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. 

mvp_badge
MVP
Rank: #69

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? +


Rank: #204

Thanks Edu and Nuno for this clarification

Rank: #1353

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?

Rank: #157
Solution

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:

  • List with 10 elements -> remove first: position 0 -> list with 9 elements
  • List with 9 elements -> remove last: position lenght - 1 -> list with 8 elements


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

Rank: #157

No problem mate, I'm glad that you managed to do it.


Kind regards,

Rui Barradas