Get random record from table (or record in a specific position)

Hello,

I’m trying to retrieve a random record from one of my tables. Is there a way to achieve it using codeless logic editor?

Using the ‘Get Object Count’ (length of my table) and ‘Random integer’ actions I can ‘point to’ a random record. However, the table designer doesn’t offer an auto-increment ID column (which I would normally use to retrieve a specific record) so I can’t use the ‘Get object by ID’ action. There is no action to retrieve a specific record by its position in a table either.

I can see there are posts on the forum which offer workarounds but they involve creating event handlers, using REST, custom code or functions. Is there no way yet to retrieve a random record using codeless logic? Alternatively, is there a proper how-to document available a newbie could follow?

I’m a new user of the platform and hoped to use the codeless logic functionaliy. The idea of having to spend a few hours digging through documentation to try and piece together a solution for this seemingly basic requirement is rather overwhelming / discouraging.

Hello @Greg_Osimowicz

  1. I might suggest that you use a random number for the offset between 0 and ‘Get Object Count’-1. You can read more about offset here: Data retrieval with Paging - Backendless REST API Documentation
  2. We have support for auto-increment column and you could use Load Table objects block with
  • pageSize: 1,
  • whereClause: auto-increment column = ‘Random integer’

Please let me know if these solutions work for you.

Regards,
Inna

Thank you for your assistance Inna!

I had previously read old forum posts about auto-increment column type missing and so I ended up not looking properly (I searched for the functionality in the calculated column type). I can see it now. Using the ‘recipe’ you’ve provided I can get a random number fine.

Regards,
Greg

1 Like