Help

Re: Creating Tasks from a Template

10793 1
cancel
Showing results for 
Search instead for 
Did you mean: 
VictoriaPlummer
7 - App Architect
7 - App Architect

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.

Image 2020-03-10 at 6.43.56 PM

Using the scripting block, I’m able to choose which event I want to apply this template to.

Screen Recording 2020-03-10 at 06.47 PM

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: [selectedEventRecord],
            "Days Out": templateRecord.getCellValue("Days Out"),
        },
    }));
    await checklistTable.createRecordsAsync(recordsToCreate);
} else {
    output.markdown("# Uh-Oh You didn't select an event!");
}
output.text("Done!");
15 Replies 15

Cool I ll check thanks

Cody_Vaught
4 - Data Explorer
4 - Data Explorer

Any way to have multiple Templates ran when there are multiple templates linked to the parent record?

Sure - I think it would just require an extra arr.map on the TemplateTypes variable.

egordin
7 - App Architect
7 - App Architect

This is fascinating - thank you @VictoriaPlummer!

Technically, could this approach be taken to run the script with an automation? I would want the inputs to your script to be fields in a given record. My goal is to recreate project pipelines similar to the ones in Daylite:
Screenshot on 2021-04-28 at 21-00-18

If I set the project stage to Delegation for example, Airtable would duplicate the tasks with the project field set to “Delegation - Template”. Am I understanding this correctly? This would be MUCH better than putting all of the required new task records individually as actions in the automation (and then having to edit them/augment them later.

@VictoriaPlummer Sorry I meant is what I’m proposing above possible, and if so, how do you recommend doing that?

@VictoriaPlummer can you please let me know how I could run this script with automation rather than a block?