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

2020-05-07 18-53-00
Rui Barradas
 
MVP
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

2019-10-21 07-27-24
Zaw Phone Thet

Rui Barradas wrote: Thank you for your replay Rui, it actually work for me.

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



2024-06-19 07-19-32
JitendraYadav

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

2016-04-22 00-29-45
Nuno Reis
 
MVP

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.


2026-01-19 17-09-56
Carlos Lessa
 
MVP

Nuno Reis wrote:

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.


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?


2024-06-19 07-19-32
JitendraYadav

Yes, I agree with Nuno.

2020-02-28 09-46-54
Eduardo Jauch

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. 

2016-04-22 00-29-45
Nuno Reis
 
MVP

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


2026-01-19 17-09-56
Carlos Lessa
 
MVP

Thanks Edu and Nuno for this clarification

2019-10-21 07-27-24
Zaw Phone Thet

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?

2020-05-07 18-53-00
Rui Barradas
 
MVP
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

2019-10-21 07-27-24
Zaw Phone Thet

Rui Barradas wrote: Thank you for your replay Rui, it actually work for me.

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



2020-05-07 18-53-00
Rui Barradas
 
MVP

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


Kind regards,

Rui Barradas

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