Skip to main content

How to Get the selected record?

  • April 12, 2020
  • 1 reply
  • 15 views

Forum|alt.badge.img+3

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

Forum|alt.badge.img+11
  • Inspiring
  • 55 replies
  • April 13, 2020

@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?