Jan 19, 2022 03:16 AM
Hi guys
I hope some of you scripting geniuses can help me.
I have a button In a task list and want to add a button to add a new row in that list under that project instead of clicking the “plus sign” underneath the row.
Can someone help me with the script?
Sinve I have the button and record picker script we know what row we’re at so to add a row/task shouldn’t be so complicated? But its complicated for me…
The script look like this know :
// Change this name to use a different table
let table = base.getTable(“Tasks”);
// Prompt the user to pick a record
// If this script is run from a button field, this will use the button’s record instead.
let record = await input.recordAsync(‘Select a record to use’, table);
if (record) {
// Customize this section to handle the selected record
// You can use record.getCellValue(“Field name”) to access
// cell values from the record
output.text(You selected this record: ${record.name}
);
} else {
output.text(‘No record was selected’);
}
Much appreciated if someone could advice.
Jesper
Solved! Go to Solution.
Jan 19, 2022 10:04 AM
Jan 19, 2022 04:40 AM
Welcome to the Airtable community!
You can use createRecordAsync
to create a new record, but you cannot control where in the user interface that new record will appear. That depends on the filtering and sorting of the current view. You can see more in the documentation.
Jan 19, 2022 05:20 AM
Hi Kuovonne!
Thanks for the feedback. I tested the createRecordAsync and as you mentioned it just adds a record all over the place:-)
I thought the button and record picker showed the location.
The task list is sorted by “Project name” and then there is “Tasks” under each project.
Each task have now the “Add task” button that I want to add a empty row under.
Is there any way to combine the record picker script and createRecordAsync to make this work?
Regards
Jesper
Jan 19, 2022 06:22 AM
The record picker gives you the record. However, the record is not aware of where it is compared to other records. Indeed, the record is not aware of other records in the table at all (unless they are linked). Records can also appear in different orders in different views. This is part of the architecture of Airtable.
Jan 19, 2022 06:55 AM
OK, understood.
Can I somehow make this work in with another approach/script?
Jan 19, 2022 07:00 AM
You can set the grouping/sorting for the view, and then create the new record with field values that will put the record in a specific place based on that grouping/sorting.
Or you can use shift+enter on the keyboard to create the new record instead of a button.
Jan 19, 2022 07:06 AM
Yes the view is already grouped by “Project”, sorry if I wasn’t clear. My bad.
Jan 19, 2022 07:10 AM
The reason for the button is that in the Interface Beta you can’t add new tasks (record picker)if there already is a record there (a task).
Jan 19, 2022 08:58 AM
A script won’t help you in an interface. Buttons that run scripts don’t work in Interfaces. Are you trying to add a new linked record? You either need to use the linked record field (not a grid) or an automation.
Jan 19, 2022 09:30 AM
Thanks kuovonne for your patience and answers.
Ok so buttons with script don’t work.
But it is a linked record field in Interfaces and I can only add a new linked record if there is non there before, see pics.