1484
Views
8
Comments
Solved
Retrieve Row Number
Question

Hi all! I'm looking for a way to get the row number of a specific record in a list. It just occurred to me that one way to do this is by looping through the list (using For Each), set a condition for the desired record, and then store the current row number. Is there a better way to do this (like perhaps a system function I don't know about)? Thanks!

mvp_badge
MVP
Rank: #89
Solution

Hi Juan Reyes,

1) If you want to get the RowNumber for the selected row in List Records or Table Records widget (Grid) you can retrieve the row number from CurrentRowNumber property i.e. you can assign an On Click action input parameter with the widget CurrentRowNumber property.

2) You can use the System action called ListIndexOf which will give you the position of the desired record as per the conditional check on each of the list element. 

Limitation: It will only give the position of the first element found in the list which satisfies the condition and the position for the rest list record which satisfies the condition will not be available.

3) If you want to have all the list record RowNumber which satisfies the search condition for desired record, I think you have to iterate the list record using the for each loop.


Kind Regards,

Benjith Sam

Staff
Rank: #452

Juan Reyes wrote:

Hi all! I'm looking for a way to get the row number of a specific record in a list. It just occurred to me that one way to do this is by looping through the list (using For Each), set a condition for the desired record, and then store the current row number. Is there a better way to do this (like perhaps a system function I don't know about)? Thanks!

Hello Juan,

You can use something like that:

Ticket.List[5].Text.Value

In this case I'm pointing to row 5.


Hope this helps,

Regards,

Cristiano

Rank: #96

There are several list functions available, for example listindex will return the (first) index of the item which matches your expression, or -1 if there is no match.

Listfilter will return a list of items which match the given expression.

mvp_badge
MVP
Rank: #89
Solution

Hi Juan Reyes,

1) If you want to get the RowNumber for the selected row in List Records or Table Records widget (Grid) you can retrieve the row number from CurrentRowNumber property i.e. you can assign an On Click action input parameter with the widget CurrentRowNumber property.

2) You can use the System action called ListIndexOf which will give you the position of the desired record as per the conditional check on each of the list element. 

Limitation: It will only give the position of the first element found in the list which satisfies the condition and the position for the rest list record which satisfies the condition will not be available.

3) If you want to have all the list record RowNumber which satisfies the search condition for desired record, I think you have to iterate the list record using the for each loop.


Kind Regards,

Benjith Sam

mvp_badge
MVP
Rank: #5

Just an observation.

Whenever you click in a line of a Table/List Records, the Table/List Records List.Current become that line, and the List.CurrentRowNumber become the Row number of that line.

You have access to those values inside a screen action called from this click. No need to pass it as InputParameter.

So, if you want the Current Row Number of a line you clicked in, inside a Screen Action, you can just use it.
If you want the index of an element in a generic list in logic, you can use ListIndex, as it was stated more than once before. Here you have a "list" of "list functions" ;)
https://success.outsystems.com/Documentation/10/Reference/Data/Data_Types/List

Cheers.

Rank: #44722

I know this topic is quite old, but I`m new in OutSystems and facing a similar problem.... I thought it would be best to use the same topic instead of creating a new one with pretty much the same issue....

I have a ForEach loop I`m comparing Current valeu agains the previous. I`m using this statement where TF is and integer variable. This comparison only occurs on rows multiple of TF so I`m using MOD() to get into it. It`s working fine but the comparison isn`t.


SyntaxEditor Code Snippet

GetCandlesBySymbol.List.Current.Candles.Close - GetCandlesBySymbol.List[GetCandlesBySymbol.List.CurrentRowNumber-TF].Candles.Close


Debugger Results:

mvp_badge
MVP
Rank: #5

Hello Renato,

The reason why we ask to open a new topic instead of replying to an old one (even more one with an answer), is that people tend to NOT look into those posts.

Also, your question is really not related to the OP question, or you were not able to explain in a way we can really make a connection, as the OP was asking for a way to find a certain RowNumber, and it seems this is not what you are trying to do.

I recommend you to open a new topic, to get more attention from the forum.

On a side note, it is not a good idea to access other elements of a list when using a ForEach. In those situations, it is better to use an Adhoc looping with an IF and a counter.

Cheers.

mvp_badge
MVP
Rank: #5

P.S. 

Also, please, explain what means "but the comparison isn`t."

Cheers