Hi all,
Hoping someone could help me correct a script. I have a base with multiple tables in it. There is a table called “Projects” and another table called “Potential Photoshoots”. I’m trying to use a script to move a single record from the “Potential Photoshoots” table to the “Projects” table. It should then delete the record from the “Potential Photoshoots” table. This all should happen automatically when a button is clicked. NOTE: The button field name and the button label are both titled “Move to Projects” and it exists on the “Potential Photoshoots” table.
I’m new to Airtable and not very proficient with scripts, but I’ve been doing research and playing around to try and learn. I was able to work out the following script, but it doesn’t move the specific record whose button was clicked. From what I understand, that is because I need to use an input.recordAsync call. I think I understand where that should go, but it seems to cause other errors in the script when I add it. I also realize that I should use the createRecordAsync call to create a single record in the “Projects” table instead of the createRecordsAsync call, but I’m not sure how to edit the rest of the script to correct the errors that occur when I make these changes. (See screenshot below to see my edited script and where the error are occurring)
//SCRIPT THAT WORKS BUT NOT FOR THE RECORD WHOSE BUTTON WAS CLICKED
let table1 = base.getTable("Potential Photoshoots");
let table2 = base.getTable("Projects");
let result = await table1.selectRecordsAsync({fields:table1.fields});
for (let record of result.records) {
if (record.getCellValue('Move to Projects')) {
await table2.createRecordsAsync([
{
fields: {
'Name': record.getCellValue("Name"),
'Category': record.getCellValue("Category"),
'Complete': record.getCellValue("Complete"),
'Due date': record.getCellValue("Due date"),
'Kickoff date': record.getCellValue("Kickoff date"),
'Launch Date': record.getCellValue("Launch Date"),
'Notes': record.getCellValue("Notes"),
'Priority': record.getCellValue("Priority"),
'Project Files': record.getCellValue("Project Files"),
'Project lead': record.getCellValue("Project lead"),
'Project Leaders': record.getCellValue("Project Leaders"),
'Project team': record.getCellValue("Project team"),
'Status': record.getCellValue("Status"),
},
}
]);
await table1.deleteRecordAsync(record.id);
}
{break;}}
Screen shot showing errors after input.recordAsync call is added and createRecordsAsync is changed to createRecordAsync:

Any help anyone could provide would be greatly appreciated!



