Help

selectRecordsAsync() not working as expected

Topic Labels: Automations
Solved
Jump to Solution
899 2
cancel
Showing results for 
Search instead for 
Did you mean: 
devdoc
6 - Interface Innovator
6 - Interface Innovator

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));

1 Solution

Accepted Solutions
TheTimeSavingCo
18 - Pluto
18 - Pluto

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

See Solution in Thread

2 Replies 2
TheTimeSavingCo
18 - Pluto
18 - Pluto

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!