jnl
jnl

Reputation: 447

Asana API - how to add subtasks to a project with a custom field

I am using the Asana API to add tasks from a website any time a node on the website is added/edited. I am adding tasks to a specific project, and adding a custom field so I can map the task back to the node. When I add a task, I check existing incomplete tasks on that project to see if any have the same node. If I find a task for the same node, I take that task's ID and set it as the parent for the new task. That way I dont have a long list of the same task, but can tell if the node was updated again.

The problem is in the new subtask is if I set the project, this new subtask is added both inside the parent task (good) but ALSO shows up in the project list like its not a subtask (bad - defeats the whole point of making it a subtask to not clutter up the task list for the project). If I do NOT set the project for this new subtask, then I get an error "Custom field with ID xxxx is not on given object".

So how can i add this subtask without it showing in the project main list?

Upvotes: 1

Views: 480

Answers (1)

Sean Wentzel
Sean Wentzel

Reputation: 165

In Asana, subtasks don't inherit the custom fields of their parent task. However, it sounds to me that you maybe don't need the custom field on the subtask (because you have it on the parent task). So when you create the subtask, you could try not setting the value of the custom field.

If you really need the custom field on the subtask: when you create the subtask, you should be able to add the subtask to both the project and the parent task while setting the custom field (at this stage it will show up in the root level of the project and as a subtask, like you noted). Then in a second API action remove it from the project (using the POST /tasks/task-id/removeProject endpoint). Asana tasks retain custom field values even if they no longer belong to the project where they originally got that custom field value (as long as the value is set).

Upvotes: 2

Related Questions