Close an item on its Planned End Date

📘

How to apply this rule?

Close Features on their Planned End Date

2238
[
  {
    "type": "source:schedule",
    "schedule": {
      "kind": "interval",
      "unit": "day",
      "value": 1
    }
  },
  {
    "type": "action:JavaScript",
    "script": "const type = \"Feature\";\nconst filter = \"Project.Name='Mobile'\";\n\nconst api = context.getService(\"targetprocess/api/v2\");\nconst workItems = await api.queryAsync(type, {\n  select: \"id\",\n  where: `EndDate=null and ${filter} and PlannedEndDate==DateTime.Today`\n});\nif (!workItems || !workItems.length) { return; }\n\nreturn workItems.map(id => {\n  return {\n    command: \"targetprocess:MoveToState\",\n    payload: {\n      resourceType: type,\n      resourceId: id,\n      stateKind: \"Final\"\n    }\n  }\n});"
  }
]