HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📌
hkob's Notion
/
ℹ️
逆引きFormula 2.0
/
💾
Database storage
/
🔗
子タスク・孫タスク・曽孫タスクのステータスをかき集めるには?
🔗

子タスク・孫タスク・曽孫タスクのステータスをかき集めるには?

Status
Created by 2.0
関数説明
📓
map
📓
flat
📓
empty
属性名
下位タスクの全ステータス
返り値
List
関連するもの
ℹ️
逆引きFormula 2.0
に戻る
Automation がリリースした後で、その使用例として子タスクのステータス更新により、開始・終了時刻を保存するとともに、親のステータスと開始・終了時刻を更新するテンプレートを配布していました。ところが、Formula 2.0 のリリースにより不具合が出てしまったため、ロールアップの部分を全て関数で書き換えました。Rollup と異なり Formula の場合には、1階層下だけでなく、さらにその下の階層まで内容を確認することができます。この仕組みを利用することで、これまで親タスクだけしか影響できなかったテンプレートが、最上位のタスクまでステータスを伝搬することができました。
ここでは、その時に利用した「子タスク・孫タスク・曽孫タスクのステータスをかき集める」仕組みを解説します。具体的には、子供がない場合には自分のステータス、子供がいる場合には再帰的に子供のステータスを回収する仕組みをしています。今回は 4 階層下までのステータスまでに限定しています。
動作確認してみたい人は、以下のテンプレートを複製してみてください。下位タスクのステータスを変更すると、上位タスクの時間とステータスが自動的に設定されます。
Automatically starts/ends parent tasks
This template automatically starts/ends parent tasks based on the states of the sub-tasks.
Automatically starts/ends parent tasks
https://www.notion.so/templates/automatically-starts-ends-parent-tasks
Automatically starts/ends parent tasks
  1. 下位階層の Status をかき集める
    1. /* 1階層目が子供を持つか? */ prop("Sub tasks").empty() ? /* 持たなければ自分(1階層目)のステータスをリストで返す */ [prop("Status")] : /* 持つ場合は2階層目の全てのページを処理 */ prop("Sub tasks").map( /* 2階層目が子供を持つか?? */ current.prop("Sub tasks").empty() ? /* 持たなければ自分(2階層目)のステータスをリストで返す */ [current.prop("Status")] : /* 持つ場合は3階層目の全てのページを処理 */ current.prop("Sub tasks").map( /* 3階層目が子供を持つか?? */ current.prop("Sub tasks").empty() ? /* 持たなければ自分(3階層目)のステータスをリストで返す */ [current.prop("Status")] : /* 持つ場合は4階層目のステータスを回収 (5階層目はチェックしない) */ current.prop("Sub tasks").map(current.prop("Status")) ) /* 3階層目の結果はリストが返るので2階層目のデータとフラットに並べる */ .flat() ) /* 2階層目の結果はリストが返るので1階層目のデータとフラットに並べる */ .flat()
      →
      📓
      empty
      📓
      map
      📓
      flat
下位タスクのステータスを回収
名前
Status
下位タスクの全ステータス
start?
complete?
Aa1
Done
Aa2
In progress
As3
Not started
Ab1
Done
Ab2
Done
Ad
Not started
A
Not started
Aa
Not started
Ab
Not started
Ac
Not started