Skip to main content
Solved

selectRecordsAsync() not working as expected

  • February 11, 2024
  • 2 replies
  • 34 views

Forum|alt.badge.img+5

below is my code but the console log doesnt give me the number of records:

async function loadRecordsAndLogCount() {
console.log("Script started - attempting to fetch records.");

try {
const table = base.getTable("Tasks");
console.log("Table 'Tasks' successfully accessed.");

// Correctly await the asynchronous call to selectRecordsAsync
const query = await table.selectRecordsAsync({
fields: ["Predecessors", "Tasks", "Next task"]
});
// Log the total number of records fetched
console.log("Records selected, total:", query.records.length);
} catch (error) {
// Log any errors encountered during the execution
console.error("Script encountered an error:", error);
}
}

// Make sure to call the async function and properly handle any uncaught errors
loadRecordsAndLogCount().catch(error => console.error("Unhandled script error:", error));

Best answer by TheTimeSavingCo

Add an await to your last line so that it's

await loadRecordsAndLogCount().catch(error => console.error("Unhandled script error:", error));

Should work fine with that change

2 replies

TheTimeSavingCo
Forum|alt.badge.img+31

Add an await to your last line so that it's

await loadRecordsAndLogCount().catch(error => console.error("Unhandled script error:", error));

Should work fine with that change


Forum|alt.badge.img+5
  • Author
  • Known Participant
  • February 11, 2024

Add an await to your last line so that it's

await loadRecordsAndLogCount().catch(error => console.error("Unhandled script error:", error));

Should work fine with that change


Awesome this worked!! Thank you so much!