How is your experience with the OutSystems Community?
129
Views
7
Comments
How to Generate Random Rows from an Aggregate

Hi, 
I have an aggregate that contains records that I want to randomly select. Is it possible to select 2 or more records and display it in a table? How?


Thank you very much.

UserImage.jpg
vikas sharma
Champion

Hi

From aggregate we access records like yourAggregateList.current.record.attribute. so it will return current record.

If you want to access any other record other than current then can write something below

Youraggregatelist.[current+1].record

So basically you can get records with the reference of current.

Hope it helps.

Regards

UserImage.jpg
vikas sharma
Champion

Hi

As you want random records from aggregate so you can achieve this by current+I in above statement. I can be any random innteger between the length of aggregate.

Regards 

2023-09-06 07-26-35
Sudip Pal

Hey Dianara,

Let's say you have 2 table you will select records from the first table and display the selected records in the 2nd table.Is this your requirement?

Thanks ,

Sudip Pal

UserImage.jpg
Dianara Bathan

Hi Supid Pal,


No, I only have one table and I plan 2 random data from that table to display it.


Thanks

2023-09-06 07-26-35
Sudip Pal

Hey Dianara,

Please check the above link.


https://www.outsystems.com/forums/discussion/79540/random-item-from-a-list-aggregate/


There is an OML in the above link's discussion use that . Your problem will be resolved without using SQL !!

Thanks,

Sudip Pal

2024-11-20 08-28-20
Pedro Marques

Hi Dianara,

You can do this more efficiently with a SQL query, like this:

Just replace the parameter @Integer by the actual number of rows that you want to retrieve. 

The ORDER BY NEWID() will make sure the records are fetched randomly.

This way you will make sure you only retrieve the records you need instead of retrieving a lot of them and then selecting a subset.

Hope this helps,

Pedro

UserImage.jpg
vikas sharma
Champion

Hi

If you want only 2 records from aggregate then easiest can be take 2 random integer. Can generate random integer by OS random method. Pass these 2 random integers in aggregate filter. Can apply filter on ID of table. As I guess ID is integer type. But ensure range of random integer is between 1 and total no of rows

Regards 

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