Help

Generating tasks for a project from a table with multiple templates (script)

1222 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Jon_Schober
4 - Data Explorer
4 - Data Explorer

Hi Airtable community!

I have a base structure where:

  • The first table is a list of email projects linked to a second table of tasks
  • The second table contains all the tasks for the email projects in the first table, grouped into “send” dates
  • A third table with a template of email tasks that are the same for each email project

I’ve implemented a script so I can generate the email template tasks with the click of a button within the first projects table:

let projectsT = base.getTable('Marketing Projects');
let tasksT = base.getTable('Project & Individual Tasks');
let taskTemplateT = base.getTable('Email Task Template');

let project = await input.recordAsync('Pick a project', projectsT);
if (project) {
    output.text(`You picked ${project.getCellValueAsString('Name')}`);
    output.text(`Creating tasks for ${project.getCellValueAsString('Name')} ... please wait`);

    let taskTemplateQ = await taskTemplateT.selectRecordsAsync();

    let projectTasks = [];

    for (let task of taskTemplateQ.records) {
        projectTasks.push(
            {
                fields: {
                    'Name': task.name,
                    'Retention Channel': { name: 'Email'},
                    'Task Status': { name: 'Not Started'},
                    'Project': [ {id: project.id} ]
                }
            }
        )
    }

    await tasksT.createRecordsAsync(projectTasks);
    output.text('Tasks created!')
}

I’m having trouble creating another template within that third table that I can choose from when going to generate tasks via the button I have in the first table. I can’t seem to figure it out with any documentation I’ve read; is there a way to incorporate a dropdown upon running the script so that I can choose which template to trigger?

2 Replies 2

I don’t think so I’m afraid

From what I can tell, your third table has like, different sets of email tasks, so email task 1, 2, 3 belong to Set A, email task 4, 5, and 6 belong to Set B?

If so I think I would end up creating a Task Template table where the records were Set A and Set B etc, and link the email tasks to those

I would then use another input.recordAsync to select the task template I needed, grab the records that are linked to the task template, and then create the records from there


As a general aside, I would highly recommend considering this comment by kuovonne about keeping the templates in the same tables as the actual data as it’s proved super helpful for my circumstances

Not a dropdown per se, but you could use input.buttonsAsync to display a series of buttons to the user. The button they click on would correspond to a email template that they wish to use.