Creating Tasks from a Template

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 from your base here
let checklist = base.getTable('Planning Check List')
let templateView = base.getTable('Planning Check List').getView('Template View');
let templateQuery = await templateView.selectRecordsAsync();
let templateRecords = templateQuery.records;
let noChecklist = base.getTable('Projects').getView('No Checklist');

// Select Event to Create Checklist
let selectedEvent = await input.recordAsync('Choose Event to Create Checklist',noChecklist);

// create the tasks
let createRecords = templateRecords.map( c => ({fields: {

        'Name': c.getCellValue('Name'),
        'Project': [selectedEvent],
        'Days Out': c.getCellValue('Days Out'),

}})
);

if(selectedEvent)await checklist.createRecordsAsync(createRecords)
else output.markdown("# Uh-Oh You didn't select an event!")

output.text('Done!');
11 Likes

This looks cool. I’m sure that many people will find it useful.

1 Like

Exactly what I was looking for!

1 Like

Very useful, thanks. How would you change the script if the Days Out field in the Projects table is a single select field type? I still want all the same Days Out values that appear in the template, but they need to copy across to a single select field in the Projects table.

I think this could help - How to create new record and select values for single select fields

@Will_Dale - I tested up converting the # of Days Field into a Single Select Field and the script still worked perfectly without modification.

If @VictoriaPlummer’s answer wasn’t clear enough, we might be able to provide more help if you explained your problem more clearly maybe with an example. What exactly are you trying to do differently than the original base?

1 Like

Thanks @Rebecca_Meritz, I actually tried to modify the script to pull data from a separate “templates” table. I think the solution where the templates just sit in the same table is more efficient, so this script works perfectly. Thanks for responding!

1 Like