The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.
Jan 11, 2021 03:22 PM
Hello out there, I am not experienced in writing code and I am hoping that someone can help me make a workflow dream come true! I’ll do my best to explain what the goal is below, but please let me know if it is unclear.
In my Program Management base, I recently followed this example to add tasks from a Task Template table to specific projects, just copying/pasting the code: https://www.airscript.dev/2020/10/04/generating-tasks-for-projects
The code copies every task from the Task Template table into the project. What I am hoping for help with is: We have several different project types, each that involves its own set of tasks. Is there a way for me to add to the above code so that I can pick a specific set of tasks in the Task Template table, based on an identifier? Currently, to separate out which project types that tasks are associated with in the Task Template table, I have a ‘multiple select’ field that includes types like Solo Exhibition, Juried Exhibition, Traveling Exhibition, etc. I chose multiple select because there are some tasks that fall under multiple project types. Ideally, this would be the situation:
I’m hoping to avoid going the way of a Zapier integration, so thank you in advance for any guidance on this!
Jan 13, 2021 04:22 PM
Well, I’m going to try to be proactive (or potentially annoying) in the hope that this post doesn’t go unnoticed for months like some. @Elias_Gomez_Sainz, @W_Vann_Hall, @Justin_Barrett– you are community leaders who I have seen post about similar queries. Do any of you have any guidance you could offer on my described workflow issue re: generating different sets of tasks for different projects? Thank you in advance :pray:
Jan 13, 2021 06:50 PM
Tagging @JonathanBowen, the author of the original script you linked above. He would be the ideal candidate for this task.
Jan 14, 2021 08:51 AM
Thanks @Justin_Barrett :slightly_smiling_face:
@Jessica_Pena - will post some thoughts on this later today
Jan 14, 2021 09:49 AM
@Jessica_Pena - we just need to extend the model and the script to accommodate different types of project templates. There’s probably a few ways to do this, but here’s my thoughts:
Base - pretty much the same as before, but we’ve got an additional “project templates” table:
Project Templates and Task Templates are a linked pair of tables that define the project type/template and the tasks for that type:
Now what we want to do in our script is pick a project that we want to set up and the template that we want to apply to it. So our script is:
let projectsT = base.getTable('Projects');
let tasksT = base.getTable('Tasks');
let projectTemplateT = base.getTable('Project Templates');
let project = await input.recordAsync('Pick a project', projectsT);
let projectTemplate = await input.recordAsync('Pick a project template', projectTemplateT);
let projectTasks = [];
if (projectTemplate) {
output.text(`Creating tasks for ${project.getCellValueAsString('Name')} using template ${projectTemplate.getCellValueAsString('Name')} ... please wait`);
for (let task of projectTemplate.getCellValue('Tasks')) {
projectTasks.push(
{
fields: {
'Task': task.name,
'Project': [ {id: project.id} ]
}
}
)
}
}
while (projectTasks.length > 0) {
await tasksT.createRecordsAsync(projectTasks.slice(0, 50));
projectTasks = projectTasks.slice(50);
}
The script flow is:
push
these tasks into an array which suitable for the Tasks tableThe create
block creates 50 task records in one go (if there are that many) - more on this here
Jan 15, 2021 01:25 AM
Okay, I plan on playing with this more tomorrow, but it looks like it is going to work– THANK YOU! I am so excited about how much time this is going to save our nonprofit so we can focus less on admin and more on our mission :grinning_face_with_big_eyes:
If I may ask another question in my pursuit to build make a magical project management base… Now that I have the Projects, Tasks, Project Templates, and Task Templates tables---- in the Task Templates table, I have a # field that notes how many days before/after an Event Date that the task should occur. In the Projects table, I have a date field that is the Event Date… my goal is that, in the Tasks table, when tasks are generated for a specific project, that the combo of Event Date (from Projects table) and Days/Before After Event that a task should occur (from Tasks Template table) will create a NEW date in the Tasks table of what day the task for that specific project should occur, so let’s say:
Can you tell me how to make this happen? :star_struck:
Jan 21, 2021 10:07 AM
Hi @Jessica_Pena - so the way I would do this is to have the "days before event’ field on the task template, like this:
Then, when the script runs, we copy this value over to the tasks table - modified script here:
let projectsT = base.getTable('Projects');
let tasksT = base.getTable('Tasks');
let projectTemplateT = base.getTable('Project Templates');
let tasksTemplateT = base.getTable('Task Templates');
let tasksTemplateQ = await tasksTemplateT.selectRecordsAsync();
let project = await input.recordAsync('Pick a project', projectsT);
let projectTemplate = await input.recordAsync('Pick a project template', projectTemplateT);
let projectTasks = [];
if (projectTemplate) {
output.text(`Creating tasks for ${project.getCellValueAsString('Name')} using template ${projectTemplate.getCellValueAsString('Name')} ... please wait`);
for (let projectTask of projectTemplate.getCellValue('Tasks')) {
let task = tasksTemplateQ.getRecord(projectTask.id);
projectTasks.push(
{
fields: {
'Task': task.name,
'Days before event': task.getCellValue('Days before event'),
'Project': [ {id: project.id} ]
}
}
)
}
}
while (projectTasks.length > 0) {
await tasksT.createRecordsAsync(projectTasks.slice(0, 50));
projectTasks = projectTasks.slice(50);
}
With the days before
value in the task table and the event date on the project table, you can combine these and come up with a date when each task needs to be complete by based on the project event date:
The “task completed by” field is:
DATEADD({Go Live Date}, {Days before event} * -1, 'days')
Feb 04, 2021 06:11 PM
Is there a template available? @JonathanBowen @Jessica_Pena
Mar 30, 2023 09:09 AM
I took this script and tried to modify it to use for my onboarding workflow base. My tables are Onboarding, Onboarding Tasks, and Onboarding Task Template. I am getting an error at line 15. Any help would be appreciated.
at main on line 15
See modified script below:
let onboardingT = base.getTable('Onboarding');
let onboardingTasksT = base.getTable('Onboarding Tasks');
let onboardingTaskTemplateT = base.getTable('Onboarding Task template');
let onboarding = await input.recordAsync('Pick a user', onboardingT);
if (onboarding) {
output.text(`You picked ${onboarding.getCellValueAsString('Name')}`);
output.text(`Creating tasks for ${onboarding.getCellValueAsString('Name')} ... please wait`);
let onboardingTaskTemplateQ = await onboardingTaskTemplateT.selectRecordsAsync();
let onboardingTasks = [];
for (let task of OnboardingTaskTemplateQ.records) {
onboardingTasks.push(
{
fields: {
'onboardingTask': onboardingtask.name,
'Onboarding': [ {id: onboarding.id} ]
}
}
)
}
await onboardingTasksT.createRecordsAsync(onboardingTasks);
output.text('Onboarding Tasks created!')
}