Turns each planned project in Notion into an Asana task with a subtask for every step, and never sends the same project twice.
Uses
AsanaNotion
Break planned projects into Asana tasks and subtasks
Every two hours, your Notion planning database is read and each project not yet sent across becomes one Asana task with a subtask for every step of the work, so it arrives already broken down rather than as one line nobody can start on.
Each task takes the row's title as its name, the row's due date if it has one, and a description linking back to Notion; the steps you listed become subtasks in the order you wrote them. The new task's id is written back to the row and only rows without one are picked up, so the same project is never sent twice. A row with no steps yet is left alone and reported rather than sent. The row is marked only once the task and every subtask exist: if a subtask cannot be created the run stops and names the project and the step, so the project is rebuilt in full next time.
Before the first run your database needs a text property named 'Steps', an empty text property named 'Asana task' and, optionally, a date property named 'Due date'.
notionDatabaseId to blank.Set notionDatabaseId to blank.asanaProjectIds to blank.Set asanaProjectIds to blank.plannedProjects to an empty list.Set plannedProjects to an empty list.notionErrorIf a step below fails, save the error as notionErrornotionDatabaseId. Save it as plannedWork.Find pages in notionDatabaseId. Save it as plannedWork.plannedProjects to plannedWork.results.Change plannedProjects to plannedWork.results.notionFailure to Could not read that Notion database: notionError.message.Set notionFailure to Could not read that Notion database: notionError.message.notionAdvice to Check the id in the 'notionDatabaseId' step, that the database is shared with your Notion connection, and that it has a text property named exactly 'Asana task'..Set notionAdvice to Check the id in the 'notionDatabaseId' step, that the database is shared with your Notion connection, and that it has a text property named exactly 'Asana task'..notionFailure plus notionAdvice.Stop and report a problem: notionFailure plus notionAdvice.createdCount to 0.Set createdCount to 0.projectRow in plannedProjects:For each projectRow in plannedProjects:projectName to blank.Set projectName to blank.titleErrorIf a step below fails, save the error as titleErrorprojectRow.title and save it as projectName.Trim projectRow.title and save it as projectName.projectName to blank.Change projectName to blank.projectName is emptyIf projectName is emptySkipped a row in the Notion database because it has no title, so there is nothing to call the Asana task..Show in the output: Skipped a row in the Notion database because it has no title, so there is nothing to call the Asana task..stepsText to blank.Set stepsText to blank.stepsErrorIf a step below fails, save the error as stepsErrorprojectRow.properties.Steps and save it as stepsText.Trim projectRow.properties.Steps and save it as stepsText.stepsText to blank.Change stepsText to blank.stepsText with ; replaced by "Split stepsText with ; replaced by
by a new line and save it as stepLines.steps to an empty list.Set steps to an empty list.stepsListed to 0.Set stepsListed to 0.stepLine in stepLines:For each stepLine in stepLines:stepLine and save it as stepName. Trim stepLine and save it as stepName.stepName isn't empty If stepName isn't emptystepsListed.Add 1 to stepsListed.steps is less than 15If the length of steps is less than 15stepName to the end of steps and save it as steps.Add stepName to the end of steps and save it as steps.steps is emptyIf steps is emptystepsListed is greater than 15If stepsListed is greater than 15stepsListed steps; only the first 15 became subtasks. Add the rest in Asana by hand.Show in the output: The Notion row '@projectName' lists stepsListed steps; only the first 15 became subtasks. Add the rest in Asana by hand.dueDate to blank.Set dueDate to blank.dueDateErrorIf a step below fails, save the error as dueDateErrorprojectRow.properties["Due date"] and save it as dueValue.Trim projectRow.properties["Due date"] and save it as dueValue.dueValue split by a space split by T and save it as dueDay.Get the first item of the first item of dueValue split by a space split by T and save it as dueDay.dueDay is 10 and dueDay contains -If the length of dueDay is 10 and dueDay contains -dueDate to dueDay.Change dueDate to dueDay.dueDate to blank.Change dueDate to blank.projectLink to blank.Set projectLink to blank.linkErrorIf a step below fails, save the error as linkErrorprojectRow.url and save it as projectLink.Trim projectRow.url and save it as projectLink.projectLink to blank.Change projectLink to blank.taskNotes to Broken out of your Notion planning database..Set taskNotes to Broken out of your Notion planning database..projectLink isn't emptyIf projectLink isn't emptytaskNotes to Broken out of your Notion planning database: projectLink.Change taskNotes to Broken out of your Notion planning database: projectLink.parentTaskId to blank.Set parentTaskId to blank.createErrorIf a step below fails, save the error as createErrorprojectName. Save it as createdTask.Create task projectName. Save it as createdTask.
Due date: dueDatetaskNotescreatedTask.gid and save it as parentTaskId.Trim createdTask.gid and save it as parentTaskId.createError.message The row was left unmarked, so it is picked up again on the next run.Show in the output: Could not create the Asana task for the Notion row '@projectName': createError.message The row was left unmarked, so it is picked up again on the next run.parentTaskId isn't emptyIf parentTaskId isn't emptystep in steps:For each step in steps:subtaskError If a step below fails, save the error as subtaskErrorstep under task parentTaskId.Create subtask step under task parentTaskId.subtaskFailure to Created the Asana task for '@projectName' but could not add the subtask '@step': subtaskError.message.Set subtaskFailure to Created the Asana task for '@projectName' but could not add the subtask '@step': subtaskError.message.subtaskAdvice to The run stopped there and the Notion row was left unmarked, so this project is built again from scratch on the next run - delete the half-built task in Asana first..Set subtaskAdvice to The run stopped there and the Notion row was left unmarked, so this project is built again from scratch on the next run - delete the half-built task in Asana first..subtaskFailure plus subtaskAdvice.Stop and report a problem: subtaskFailure plus subtaskAdvice.writeBackErrorIf a step below fails, save the error as writeBackErrorprojectRow.Update projectRow.createdCount.Add 1 to createdCount.writeBackFailure to Broke the Notion row '@projectName' out into Asana but could not record the task id on that row: writeBackError.message.Set writeBackFailure to Broke the Notion row '@projectName' out into Asana but could not record the task id on that row: writeBackError.message.writeBackAdvice to The run stopped there rather than send the rest of the database across twice. Check that the database has a text property named exactly 'Asana task' that Lodol is allowed to edit..Set writeBackAdvice to The run stopped there rather than send the rest of the database across twice. Check that the database has a text property named exactly 'Asana task' that Lodol is allowed to edit..writeBackFailure plus writeBackAdvice.Stop and report a problem: writeBackFailure plus writeBackAdvice.createdCount planned project(s) out of Notion into Asana tasks with subtasks.Show in the output: Broke createdCount planned project(s) out of Notion into Asana tasks with subtasks.