The query that is returned on the third line contains all records in the table, but not necessarily in a predictable order. Deleting the first record in that array won’t necessarily mean that you’re deleting the record where you clicked the button.
The way to capture the specific record where a button was clicked is by using
input.recordAsync(). Here’s your script modified to use that:
// Delete a record in the Tasks table
let table = base.getTable("Tasks");
let clickedRecord = await input.recordAsync("Pick a record", table);
console.log("Deleted a record!");
If you run the script manually, you’ll be prompted to choose a record. However, clicking a button in a button field that targets this script will bypass the prompt and assign that record to the listed variable (
clickedRecord in this case).
For future reference, I recommend styling any code/formula samples that you want to share with the preformatted text styling option in the post editor (the toolbar button looks like this: