Afternoon all, i am attempting to pick a random record from an aggregate to then be put into a variable. however I am unsure how to do this. picking a random identifier would be suitable but just not sure the process. any help is welcome. TIA
Hi Maxwell,
You can also achieve it through JavaScript as well you can generate a random number using random() function first you need to get the total count of the aggregate then pass it in your JavaScript through input parameter
it will return a random number, you can use it to fetch the data from aggregate.
I have attached OML for the reference.
Sample- Link
I hope this will help
Thanks
Tousif khan
Hello Maxwell,
I would suggest not picking a random identifier but maybe a random index of the list.
An easy way to do this is :
Hope it helps!
Paulo Rosário
Hi Can you please share the oml file
You can get total items from aggregate count properties. You can use below forge component to get random integer between a minimal and maximal value.
https://www.outsystems.com/forge/component-overview/677/randomizer-number-generator
To get the random item from aggregates you can use list index like - GetProducts.List[0]
So whatever random number you get from the component you can use that in aggregates like - GetProducts.List[randominteger]
Vinod
Hi @Maxwell Mckinnon
You can create SQL query and to select random Id use NEWID()
you can take reference from stackoverflow https://stackoverflow.com/questions/848872/select-n-random-rows-from-sql-server-table
Thanks,Shriyash