Help

Re: Create tasks for template - repeat for multiple projects

Solved
Jump to Solution
869 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Saskcraftcounci
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi all, I've been a fly on the wall in the community for a while now, today I need some help. 

I reviewed this post to help me with my problem, however I'm still running into issues I can't seem to get around with my current ability. For reference, I'm getting comfortable with formulas, but have no scripting/coding experience. 

https://community.airtable.com/t5/other-questions/create-tasks-from-templates-table-via-button-autom... 

I need a template of tasks, like in the above post; but I need to be able to repeat these tasks for several projects. I've managed to get this above suggestion to work, but it turns out that I need to be able to make NEW tasks that aren't linked to each other, every time I trigger my automations.

E.g. 

My base is built of three significant tables. A 'To Do list"  table; a Projects table; and now a task template table.

The To Do list table consists of tasks, linked to the Projects table. So that table has a list of projects, such as

Exhibition 340, exhibition 341, exhibition 342, Special project A, Special Project B, Admin Work 1, etc... 

with the above community post that I followed, any tasks I link to a Project (Exhibition 340 or 341), is only ONE task, attached to each project. So, If I check off the task "write press release" for Exhibition 340, it "checks" it off for Exhibition 341 and 342. I work on several projects at once, so I can't simply go uncheck all my tasks when a new project begins. 

Does anyone have any suggestions? 

Thank you in advance!

 

2 Solutions

Accepted Solutions
Josh_Colina
6 - Interface Innovator
6 - Interface Innovator

Hi there! I haven't tried the solution that you linked above, but I've used this script in my bases to great effect and recommend giving it a go! This script will create unique tasks parented to your project, and furthermore allows you to establish dependencies if that is something that would be helpful!

The only parts of the script that you'll need to edit are on these lines, where you'll simply align the script syntax to your base's table and view names

const project_table_name = 'Projects';
const new_project_view_name = 'New Projects';
const project_template_link_field_name = 'Project Template';

const task_table_name = 'Tasks';
const task_project_link_field_name = 'Projects';
const task_dependency_field_name = 'Followed By';
const task_primary_field_name = 'Task Name';
const project_template_table_name = 'Project Templates';
const task_template_table_name = 'Task Templates';
const proj_temp_task_temp_link_field_name = 'Tasks';
const task_temp_dependency_field_name = 'Followed By';
const task_temp_primary_field_name = 'Task Name';

 Big shout out to the team that developed this, it's definitely saved my hide!

See Solution in Thread

Sure! When I incorporated this into my base, I added my extra data into this section (here for example, let's pretend you wanted to add a templatized number of hours for the tasks - I've added that field in this example)

const task_table_name = 'Tasks';
const task_project_link_field_name = 'Projects';
const task_dependency_field_name = 'Followed By';
const task_primary_field_name = 'Task Name';
const task_expected_hours_field_name = 'Expected Hours'

const project_template_table_name = 'Asset Templates';
const task_template_table_name = 'Task Templates';
const proj_temp_task_temp_link_field_name = 'Associated Tasks';
const task_temp_dependency_field_name = 'Preceded By';
const task_temp_expected_hours_field_name = 'Expected Hours Template';
const task_temp_primary_field_name = 'Name';

 Then basically wherever in the script I found the existing and defined variables (for example task_primary_field_name) I just copied and pasted the line but swapped out the variable for my new field

  for(let t of task_temps) {
        payloads.push({
            fields: {
                [task_project_link_field_name]: [{id: r.id}],
                [task_primary_field_name]: t.getCellValueAsString(task_temp_primary_field_name),
                [task_expected_hours_field_name]: t.getCellValueAsString(task_temp_expected_hours_field_name),
                [task_to_template_link_field_name]: t.id

The catch that I ran into here (without enough scripting experience to further edit this script) is that these additional fields have to be Single-line text fields. This might not be a problem for templatized data like dates or numbers, since you can use a formula in another field to transform the output from a string, but it may pose an issue if you'd like to templatize attachment fields or long text.

See Solution in Thread

5 Replies 5
Josh_Colina
6 - Interface Innovator
6 - Interface Innovator

Hi there! I haven't tried the solution that you linked above, but I've used this script in my bases to great effect and recommend giving it a go! This script will create unique tasks parented to your project, and furthermore allows you to establish dependencies if that is something that would be helpful!

The only parts of the script that you'll need to edit are on these lines, where you'll simply align the script syntax to your base's table and view names

const project_table_name = 'Projects';
const new_project_view_name = 'New Projects';
const project_template_link_field_name = 'Project Template';

const task_table_name = 'Tasks';
const task_project_link_field_name = 'Projects';
const task_dependency_field_name = 'Followed By';
const task_primary_field_name = 'Task Name';
const project_template_table_name = 'Project Templates';
const task_template_table_name = 'Task Templates';
const proj_temp_task_temp_link_field_name = 'Tasks';
const task_temp_dependency_field_name = 'Followed By';
const task_temp_primary_field_name = 'Task Name';

 Big shout out to the team that developed this, it's definitely saved my hide!

I'll try this today and let you know how it goes! Thanks so much!

Hi Josh, thanks again for sharing this. It's much simpler to use than the previous work I was trying. I've looked at answers on the original post but couldn't find this out - is there a way to have the newly created tasks include additional fields/data? I see the section "this is the part of the script where you assign what data..." but I can't figure out how to add additional fields - long text for example, where notes on the task can be included for every project. Here's the section I think needs to be altered, but I haven't been able to figure it out so far.
Any tips?  TIA!

// THIS IS THE PART OF THE SCRIPT WHERE YOU ASSIGN WHAT DATA YOU WANT IN YOUR NEWLY CREATED TASKS
//
output.markdown('### Creating new tasks')
output.markdown(`Found **${new_project_results.records.length}** projects which need task assignment`)
var payloads = [];
for(let r of new_project_results.records){
    // there should only ever be one project template linked
    // so just take the first one
    let p_id = r.getCellValue(project_template_link_field_name)[0].id;

    let task_temp_ids = project_task_temp_map[p_id];
    let task_temps = task_temp_ids.map((i)=>{
        return task_temp_results.getRecord(i);
    });
    for(let t of task_temps) {
        payloads.push({
            fields: {
                [task_project_link_field_name]: [{id: r.id}],
                [task_primary_field_name]: t.getCellValueAsString(task_temp_primary_field_name),
                [task_to_template_link_field_name]: t.id
            }
        });
    }
}

"

Sure! When I incorporated this into my base, I added my extra data into this section (here for example, let's pretend you wanted to add a templatized number of hours for the tasks - I've added that field in this example)

const task_table_name = 'Tasks';
const task_project_link_field_name = 'Projects';
const task_dependency_field_name = 'Followed By';
const task_primary_field_name = 'Task Name';
const task_expected_hours_field_name = 'Expected Hours'

const project_template_table_name = 'Asset Templates';
const task_template_table_name = 'Task Templates';
const proj_temp_task_temp_link_field_name = 'Associated Tasks';
const task_temp_dependency_field_name = 'Preceded By';
const task_temp_expected_hours_field_name = 'Expected Hours Template';
const task_temp_primary_field_name = 'Name';

 Then basically wherever in the script I found the existing and defined variables (for example task_primary_field_name) I just copied and pasted the line but swapped out the variable for my new field

  for(let t of task_temps) {
        payloads.push({
            fields: {
                [task_project_link_field_name]: [{id: r.id}],
                [task_primary_field_name]: t.getCellValueAsString(task_temp_primary_field_name),
                [task_expected_hours_field_name]: t.getCellValueAsString(task_temp_expected_hours_field_name),
                [task_to_template_link_field_name]: t.id

The catch that I ran into here (without enough scripting experience to further edit this script) is that these additional fields have to be Single-line text fields. This might not be a problem for templatized data like dates or numbers, since you can use a formula in another field to transform the output from a string, but it may pose an issue if you'd like to templatize attachment fields or long text.

Thanks so much for your response!  This is perfect, I followed your directions and managed to get my 'notes' section to be created with my tasks (as a single select field). I was hoping for a solution to have long text, so i can use a 'sub-checklist' copy through, but I'm sure I can think of how to structure this in a way that supports the single line text use. 

Thanks again!