Skip to main content

Creating Tasks from a Template

  • March 10, 2020
  • 15 replies
  • 263 views

Forum|alt.badge.img+4

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: [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

kuovonne
Forum|alt.badge.img+29
  • Brainy
  • March 12, 2020

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


Forum|alt.badge.img+14

Exactly what I was looking for!


Forum|alt.badge.img+2
  • Participating Frequently
  • May 24, 2020

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.


Forum|alt.badge.img+4

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


  • Participating Frequently
  • May 26, 2020

@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?


Forum|alt.badge.img+2
  • Participating Frequently
  • June 20, 2020

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!


Forum|alt.badge.img
  • Known Participant
  • February 26, 2021

Thanks for this script !
Is there any way we can use this script as the following :

  • Creating task according to multiple select task field (if field 1 selected, then create a task list, if field 2 selected, then create another template task …)
  • Can we use the script to work with script automation ?

thanks !!


Forum|alt.badge.img+1
  • New Participant
  • March 2, 2021

Thank you for this script! It’s very helpful.

Is there a way that to adapt this for multiple templates for different types of projects (e.g., “webinar briefing” or “op-ed”). I like that the script prompts us to select a project, but I’m not sure how to prompt it to ask which template to use.


Forum|alt.badge.img+4

Thank you for this script! It’s very helpful.

Is there a way that to adapt this for multiple templates for different types of projects (e.g., “webinar briefing” or “op-ed”). I like that the script prompts us to select a project, but I’m not sure how to prompt it to ask which template to use.


@Alter345 and @CPC_Center - both great questions and this is totally doable. I updated the script in the example base so that you can choose between the Webinar or Party Template


Forum|alt.badge.img
  • Known Participant
  • March 18, 2021

@Alter345 and @CPC_Center - both great questions and this is totally doable. I updated the script in the example base so that you can choose between the Webinar or Party Template


Cool I ll check thanks


  • New Participant
  • March 19, 2021

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


Forum|alt.badge.img+4

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
Forum|alt.badge.img+15
  • Known Participant
  • April 29, 2021

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:

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.


egordin
Forum|alt.badge.img+15
  • Known Participant
  • May 3, 2021

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:

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?


egordin
Forum|alt.badge.img+15
  • Known Participant
  • May 21, 2021

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


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