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:
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": pproject],
}
}
});
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);