run scriptの第2弾を作ってみました。
今回は次のシチュエーションを想定しました。
サブタスクが全て完了したら親タスクを完了にして進捗管理する運用をしていて、サブタスクを何かの理由で再実行する場合、親タスクも未完了に戻すルールにしていたとします。
しかし、親タスクを未完了にするのを忘れてしまうことも多いと思います。
そこで、ルールでサブタスクが未完了に戻ったら、親タスクを未完了に戻すことで、戻し忘れを防止したいと思います。
スクリプトは次のようになります。
/**
* What's in scope?
* 1. (string) project_gid, workspace_gid, task_gid (only if triggered on a task)
* 2. (function) log - this behaves like console.log and takes any number of parameters
* 3. (object) *ApiInstance - for each group of APIs, an object containing functions to call the APIs; for example:
* tasksApiInstance.getTask(...)
* goalsApiInstance.addFollowers(...)
* For more info, see https://github.com/Asana/node-asana
*/
async function run() {
// 親タスクを取得
const task = await tasksApiInstance.getTask(task_gid);
parent_gid = task.data.parent?.gid
if(!parent_gid){
log("this task has no parent tasks.");
return;
}
let body = {
"data":{
"completed": false
}
}
await tasksApiInstance.updateTask(body, parent_gid);
}
// To function properly, the script must end with returning a Promise via run().
run();
ルールは次のようになります。run scriptアクションに上のコードを貼り付けます。
サブタスクをトリガーにするので、トリガー設定をサブタスクで実行にします。