Get a random record using Obj-Browse in Activity

I would like to know if is there any way to fetch/browse a random record using Obj-Browse. Generally whenever I browse using pyID is not null in the filter, it gives records in descending order but In my requirement, the Max records are 1 only. Instead of getting 1st record in the list of descending order records, I need to get a random record from all the records that exist. Please let me know if we have any solution to this.

@BhaskarSaiTejaG You can make use of connect-sql rule with the below statement

select pyID AS “.pyID” from tablename order by random()

in the rdb-list you can specify maxrecords as 1

@BhanuPrakash_G Thanks. but it is not a better approach to use Connect-SQL with RDB-List. right?

@BhaskarSaiTejaG This can be an option, you could start by assigning a random value to a property used in the class you specified in Obj-Browse. For example, if pyID is a numeric value, you can initially set Param.pyID using a function from the expression builder (check: https://support.pega.com/question/how-generate-random-number-within-two-limits) and then utilize it as a filter.

@RoseV Thanks but it does not work as per my requirement. because I have only certain pyID values, not all pyID values. It is not suitable for my requirements. Do we have any other option to filter random value from certain records?

@BhaskarSaiTejaG If possible, consider adopting an alternative approach. You might explore the use of a report definition along with a function as a filter. You can call pxRetrieveReportData activity to call a RD in an activity. An example of this approach can be found in the following links: