Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

Can airtable chose a record randomly?

Solved
Jump to Solution
5277 3
cancel
Showing results for 
Search instead for 
Did you mean: 
Nathan_Ramey
6 - Interface Innovator
6 - Interface Innovator

Hello everybody! I was wondering is there a way to make it so that airtable and chose a record randomly?

1 Solution

Accepted Solutions

Sure try this. Make sure you are viewing the table and view, then run the script.

let curTable = cursor.activeTableId
let curView = cursor.activeViewId
let table = base.getTable(curTable)
let view = table.getView(curView)
let queryRecords = await view.selectRecordsAsync()
let recCount = queryRecords.records.length
let randomNumber = Math.floor(Math.random() * recCount);
let randRecord = queryRecords.records[randomNumber]
output.markdown(`
**Random Record**

Record ID: [${randRecord.id}](http://airtable.com/${base.id}/${table.id}/${randRecord.id})

Record Name: ${randRecord.name}
`)

See Solution in Thread

3 Replies 3
Vivid-Squid
11 - Venus
11 - Venus

Hi @Nathan_Ramey,
If you add the scripting extension, paste this code in to replace what ever is there. It will return one random record from the table you are currently viewing.

let curTable = cursor.activeTableId
let table = base.getTable(curTable)
let queryRecords = await table.selectRecordsAsync()
let recCount = queryRecords.records.length
let randomNumber = Math.floor(Math.random() * recCount);
let randRecord = queryRecords.records[randomNumber]
output.markdown(`
**Random Record**

Record ID: [${randRecord.id}](http://airtable.com/${base.id}/${table.id}/${randRecord.id})

Record Name: ${randRecord.name}
`)

image

Nathan_Ramey
6 - Interface Innovator
6 - Interface Innovator

Thank you! I was wondering could this be applied to a particular view? @Vivid-Squid

Sure try this. Make sure you are viewing the table and view, then run the script.

let curTable = cursor.activeTableId
let curView = cursor.activeViewId
let table = base.getTable(curTable)
let view = table.getView(curView)
let queryRecords = await view.selectRecordsAsync()
let recCount = queryRecords.records.length
let randomNumber = Math.floor(Math.random() * recCount);
let randRecord = queryRecords.records[randomNumber]
output.markdown(`
**Random Record**

Record ID: [${randRecord.id}](http://airtable.com/${base.id}/${table.id}/${randRecord.id})

Record Name: ${randRecord.name}
`)