
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Sep 29, 2022 08:02 AM
Hello everybody! I was wondering is there a way to make it so that airtable and chose a record randomly?
Solved! Go to Solution.
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Sep 29, 2022 09:10 AM
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}
`)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Sep 29, 2022 08:34 AM
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}
`)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Sep 29, 2022 08:59 AM
Thank you! I was wondering could this be applied to a particular view? @Vivid-Squid

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎Sep 29, 2022 09:10 AM
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}
`)
