Help

Welcome to the Airtable Community! If you're new here, check out our Getting Started area to get the most out of your community experience.

How to Get the selected record?

Topic Labels: Custom extensions
711 1
cancel
Showing results for 
Search instead for 
Did you mean: 

This does not work. It throws some exceptions.

useLoadable(cursor);
useWatchable(cursor, ['activeTableId', 'selectedRecordIds']);
const table = base.getTableById(cursor.activeTableId);
const record = useRecordById(table, cursor.selectedRecordIds[0]);

This works. But is this the correct way to do it? Feels like there should be a much simpler way to do this.

useLoadable(cursor);
useWatchable(cursor, ['activeTableId', 'selectedRecordIds']);
const table = base.getTableById(cursor.activeTableId);
const queryResult = table.selectRecords();
let record = null;
try {
    record = queryResult.getRecordById(cursor.selectedRecordIds[0]);
} catch (e) {
    record = null;
}
1 Reply 1

@Ashwin_P What version of the SDK are you using? Support for useRecordById(table, recordId) was added in 0.0.42 (you can view the changelog here).

If that doesn’t fix it, can you share what exceptions are being thrown?