# How to update a task state when all subtasks related to it have a certain state

**URL:** <https://community.fibery.io/t/how-to-update-a-task-state-when-all-subtasks-related-to-it-have-a-certain-state/4043>\
**Category:** Get Help\
**Created:** [February 23, 2023, 10:12am UTC](https://community.fibery.io/t/how-to-update-a-task-state-when-all-subtasks-related-to-it-have-a-certain-state/4043 "2023-02-23T10:12:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![A\_Sleman](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/a_sleman/32/6279_2.png) [@A\_Sleman](https://community.fibery.io/u/A_Sleman)\
**Post date:** [February 23, 2023, 10:12am UTC](https://community.fibery.io/t/how-to-update-a-task-state-when-all-subtasks-related-to-it-have-a-certain-state/4043/1 "2023-02-23T10:12:29Z")

</div>

Hi !  
i have 2 databases for tasks that are related to each other one is called tasks and the other is subtasks. they both have the same state options ( open, in progress and done).  
i Have been trying to create an automation where the first rule makes the state of the parent task be set to in progress if one or more subtasks are in progress state, and the second makes the task state done if all the subtasks are done.  
does anyone have an idea of how this might be accomplished ?

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 23, 2023, 10:39am UTC](https://community.fibery.io/t/how-to-update-a-task-state-when-all-subtasks-related-to-it-have-a-certain-state/4043/2 "2023-02-23T10:39:36Z")

</div>

I would suggest creating a couple of formula fields in the Task db:

`Subtasks.Filter(State.Name = "In Progress").Count() > 0`

`Subtasks.Filter(State.Name = "Done").Count() = Subtasks.Count()`

The first formula will be true if there are any subtasks in progress, the second will be true if all subtasks are done.

Then you can define a couple of automations.  
One should trigger on the first field updating (and filter to the case where it is true) with an action to set the task state to In Progress.  
The other should trigger on the second field updating (and filter to the case where it is true) with an action to set the task state to Done.

By the way, is there a reason why you are using two databases, when you could just use one database and a ‘self-relation’ so that each Task can link to multiple other Tasks (which would be the subtasks)?

---

<div class="post-metadata">

**Author:** ![A\_Sleman](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/a_sleman/32/6279_2.png) [@A\_Sleman](https://community.fibery.io/u/A_Sleman)\
**Post date:** [February 23, 2023, 2:32pm UTC](https://community.fibery.io/t/how-to-update-a-task-state-when-all-subtasks-related-to-it-have-a-certain-state/4043/3 "2023-02-23T14:32:51Z")

</div>

Thank you for replying  
your suggestion has worked, however the second formula is displaying true state when the task has no subtasks is there a way to fix it, because I’m new to formulas and can’t figure it out.  
I’m using separate databases because in my opinion it’s easier to manage them that way.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 23, 2023, 2:37pm UTC](https://community.fibery.io/t/how-to-update-a-task-state-when-all-subtasks-related-to-it-have-a-certain-state/4043/4 "2023-02-23T14:37:56Z")

</div>

`(Subtasks.Filter(State.Name = "Done").Count() = Subtasks.Count()) AND Subtasks.Count() > 0`

> [@A\_Sleman](#):
>
> the second formula is displaying true state when the task has no subtasks

I guess I assumed that if a Task has no subtasks, then there are no subtasks which are not done.  
This seemed to be logical behaviour to me, but you can use the above if you want the opposite.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 23, 2023, 2:40pm UTC](https://community.fibery.io/t/how-to-update-a-task-state-when-all-subtasks-related-to-it-have-a-certain-state/4043/5 "2023-02-23T14:40:48Z")

</div>

> [@A\_Sleman](#):
>
> I’m using separate databases because in my opinion it’s easier to manage them that way.

Out of curiosity, what are the things that are easier with 2 databases (or what is harder with just one?)

---

<div class="post-metadata">

**Author:** ![A\_Sleman](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/a_sleman/32/6279_2.png) [@A\_Sleman](https://community.fibery.io/u/A_Sleman)\
**Post date:** [February 23, 2023, 3:00pm UTC](https://community.fibery.io/t/how-to-update-a-task-state-when-all-subtasks-related-to-it-have-a-certain-state/4043/6 "2023-02-23T15:00:32Z")

</div>

Thank you for replying again.  
I use 2 databases because i don’t want to have a lot of fields in the same database as it gets daunting to manage, because the tasks and subtasks require different fields such as: separate date fields for subtasks and tasks, a description for both tasks and subtasks, and so on.

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [February 23, 2023, 3:02pm UTC](https://community.fibery.io/t/how-to-update-a-task-state-when-all-subtasks-related-to-it-have-a-certain-state/4043/7 "2023-02-23T15:02:32Z")

</div>

> [@A\_Sleman](#):
>
> I use 2 databases because i don’t want to have a lot of fields in the same database as it gets daunting to manage, because the tasks and subtasks require different fields such as: separate date fields for subtasks and tasks, a description for both tasks and subtasks, and so on.

Thanks for that. It’s always interesting to understand other people’s use cases 🙏

---

<div class="post-metadata">

**Author:** ![A\_Sleman](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/a_sleman/32/6279_2.png) [@A\_Sleman](https://community.fibery.io/u/A_Sleman)\
**Post date:** [February 23, 2023, 3:19pm UTC](https://community.fibery.io/t/how-to-update-a-task-state-when-all-subtasks-related-to-it-have-a-certain-state/4043/8 "2023-02-23T15:19:28Z")

</div>

any time 👍
