Is there a way to iterate over a LookupTable or list in reverse order?

Hi Pega,

In my solution I’m creating a LookupTable. If I were to use a ListLoop to iterate through all the records, the record that has been put in first, will be iterated through first.

In my case I want my loop to start at the last record of the LookupTable. Is there an easy way of doing this? Without having to change the way I import the data in the LookupTable?

I’m thinking about (list)looping through all the keys and putting them all in a list whereafter I would reverse this list somehow.

I’m glad to hear any suggestions.

In the end I solved this problem by changing the way I got the data in the LookupTable (reverse order).

I’m still curious is there would have been a better way.

This is bizarre. I posted a reply with a sample solution and it is not appearing. Here is a sample though. Basically, I would manipulate the data in the underlying DataTable within the LookpTable. I found a simple example online that involves creating a clone of the original DataTable and re-inserting records into it backwards. Obviously, this isn’t the most efficient sort, but I am not aware of a way to simply sort an entire DataTable without specifying a column to sort on (which might change your order). This solution is probably fine enough though more DataSets under 100k.

In my solution, you’ll notice I seeded the DataTable from a script as this was the most efficient way to get thousands of records into the table. I also made sure to specify the DataSource after the table was seeded as many changes to the DataSet in a DataGridView tends to lock up the UI thread.

Project41.zip (18.8 KB)

I looked into your project. The script is a fast way to completely reverse a DataTable, it works really well. Thanks for the time and effort you put into this.