Help

Re: Automate Tasks for Projects including Dependencies via a script

Solved
Jump to Solution
1045 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Yonatan_Langer
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi everyone

I hope for your help to improve an existing script for automating tasks for projects. 

I have courses and classes where we always have repetitive tasks in order to organize the courses.

In order to avoid creating always the same tasks, I created templates with tasks and a script that copies the standard tasks to the task sheet, and assigns them to the person that need to deal with them.

For example: each course need a zoom link, a graphic and a registration page. By selecting the template, these three tasks get copied and assigned automatically.

So far so good. Now I want to add dependencies of the tasks in the template, because some tasks should have the status on hold, until a pre-requisite task is completed.

The names of the tasks will repeat themselves, and when copying the tasks from the template to the task sheet I don’t know how to assign the right dependent task.

This is the template sheet:

 

Yonatan_Langer_1-1686131952943.png

 

Below is my script:

// @ts-nocheck

// Select project 

// Understand what type of project it is

// User input which project needs action item

// Find action items that match the project type that the user selected

// Duplicate those templates into live action items

let projects = base.getTable("Classes");

let projectsView = projects.getView("Classes without tasks");

let project = await input.recordAsync("Select classes to create task items for", projectsView);

console.log(project);

// Find task template items that match the Task template type that the user selected

// Load all templates items

let templateItemsTable = base.getTable("Template Items");

let allTemplateItems = await templateItemsTable.selectRecordsAsync();

let templateItems = allTemplateItems.records.filter(templateItem => {

// Check whether action Items matching request

   return templateItem.getCellValueAsString("Task Template") === project.getCellValueAsString("Template")

});

// Duplicate those templates into live action item

// Get the name of the template action items

// Associate to the right project 

// Copy over the team's that is responsible

let actionItems = templateItems.map(templateItem => {

    return {

        fields: {

            "Task Name":    templateItem.getCellValue("Name"),

            "Task Order":   templateItem.getCellValue("Order"),

            "Notes":        templateItem.getCellValue("Notes"),

            "Attachments":  templateItem.getCellValue("Attachments"),

            "Collaborator": templateItem.getCellValue("Collaborator"),

            "Item Type":    templateItem.getCellValue("Item Type"),

            "Status":       templateItem.getCellValue("Status"),

            "URL":          templateItem.getCellValue("URL"),

            "Classes Link": [project],

       }

    }

});

let workItemsTable = base.getTable("Tasks");

while (actionItems.length > 0) {

            await workItemsTable.createRecordsAsync(actionItems.slice(0, 50));

            actionItems = actionItems.slice(50);

        }

        //old code with batch size issue: await workItemsTable.createRecordsAsync(actionItems);

 

1 Solution

Accepted Solutions
Stephen_Orr1
10 - Mercury
10 - Mercury

Hi @Yonatan_Langer,

I have scripted something similar for project management and this great post by @Giovanni_Briggs helped me tackle the dependency piece.

https://community.airtable.com/t5/development-apis/creating-projects-tasks-from-templates-via-script...

That said, have you given record templates a look? This wasn't available to me back then and I'd like to take some credit for its inception but who knows 🙂

Hope this helps!
-Stephen

 

See Solution in Thread

4 Replies 4
Stephen_Orr1
10 - Mercury
10 - Mercury

Hi @Yonatan_Langer,

I have scripted something similar for project management and this great post by @Giovanni_Briggs helped me tackle the dependency piece.

https://community.airtable.com/t5/development-apis/creating-projects-tasks-from-templates-via-script...

That said, have you given record templates a look? This wasn't available to me back then and I'd like to take some credit for its inception but who knows 🙂

Hope this helps!
-Stephen

 

Hi Stephen, thank you for showing me Record Templates! Thats a game changer, I can do everything I wanted regarding automation of task templates with that. Thank you sooo much!

Yonatan

Hello Stephen, thank you again for pointing out Record Templates. Since there is a limitation of 100 records per base, I have to also use Automations that will trigger a script to assign task templates with dependencies. 

I saw the post from Giovanni, but the script only seems to work in the script editor and not in Automation, due to output.markdown

Do you have experience adjusting the template he has for Automation?

Best

Yonatan

Hi Stephen, 

this is my curent code which is used in script editor. I want to use it in Automation instead and need help with two updates:

1. Select automatically the record (right now a button triggers the script)

2. Assign Dependent Tasks from the Task Template

 

// @ts-nocheck
// Select project 

// Understand what type of project it is

// User input which project needs action item

// Find action items that match the project type that the user selected
// Duplicate those templates into live action items

let projects = base.getTable("Courses");


let projectsView = projects.getView("New Projects");

let project = await input.recordAsync("Select classes to create task items for", projectsView);

console.log(project);


// Find task template items that match the Task template type that the user selected

// Load all templates items

let templateItemsTable = base.getTable("Template Items");

let allTemplateItems = await templateItemsTable.selectRecordsAsync();


let templateItems = allTemplateItems.records.filter(templateItem => {

// Check whether action Items matching request

   return templateItem.getCellValueAsString("Task Template") === project.getCellValueAsString("Task Template")

});

// Duplicate those templates into live action item

// Get the name of the template action items

// Associate to the right project 

// Copy over the team's that is responsible


let actionItems = templateItems.map(templateItem => {

    return {


        fields: {

            "Task Name":    templateItem.getCellValue("Name"),
            "Task Order":   templateItem.getCellValue("Order"),
            "Notes":        templateItem.getCellValue("Notes"),
            "Attachments":  templateItem.getCellValue("Attachments"),
            "Collaborator": templateItem.getCellValue("Collaborator"),
            "Item Type":    templateItem.getCellValue("Item Type"),
            "URL":          templateItem.getCellValue("URL"),
            "Status Formula":          templateItem.getCellValue("Status Formula"),
            "Courses": [project],
            "Days": templateItem.getCellValue ("Days")
            
            
         
            

        }

    }

});



let workItemsTable = base.getTable("Tasks");






while (actionItems.length > 0) {
            await workItemsTable.createRecordsAsync(actionItems.slice(0, 50));
            actionItems = actionItems.slice(50);
        }

        //old code with batch size issue: await workItemsTable.createRecordsAsync(actionItems);