Okay so I’ve got a list of pretty standard tasks every time I host an event, so I’d like to automatically add them to my task list for each new event I add to my table. Below I have my template of tasks.
Using the scripting block, I’m able to choose which event I want to apply this template to.
Take a peek at the script below (which borrows heavily from the Record Template example), and example base here! Would love to know you how use this, and if it’s helpful.
// pick tables & views from your base here
let checklistTable = base.getTable("Planning Check List");
let templateView = checklistTable.getView("Template View");
let projectsTable = base.getTable("Projects");
let projectsWithNoChecklistView = projectsTable.getView("No Checklist");
// select an event to create a checklist for
let selectedEventRecord = await input.recordAsync(
"Choose event to create checklist for",
projectsWithNoChecklistView
);
if (selectedEventRecord) {
// load in all of of the tasks that our in our template
let templateQuery = await templateView.selectRecordsAsync();
let templateRecords = templateQuery.records;
// create new tasks based on the template
let recordsToCreate = templateRecords.map((templateRecord) => ({
fields: {
Name: templateRecord.getCellValue("Name"),
Project: rselectedEventRecord],
"Days Out": templateRecord.getCellValue("Days Out"),
},
}));
await checklistTable.createRecordsAsync(recordsToCreate);
} else {
output.markdown("# Uh-Oh You didn't select an event!");
}
output.text("Done!");