Close User Stories that stayed more than 10 days in a particular state

The rule automatically closes User Stories that stayed more than 10 days in a specific state - "Tested" in the example.

📘

How to apply this rule?

1135

🚧

Replace the name of the Entity State with the real one in the code line 4.

[
  {
    "type": "source:schedule",
    "schedule": {
      "kind": "interval",
      "value": 1,
      "unit": "day"
    }
  },
  {
    "type": "action:JavaScript",
    "script": "//Type of the entity\nconst ENTITYTYPE = \"UserStory\";\n//If the card is now in this state\nconst STATE = \"Tested\";\n//And it stayed in this state for more than this amount of days\nconst DAYS = 10;\n\nconst api = context.getService(\"targetprocess/api/v2\");\n\nconst entities = await api.queryAsync(ENTITYTYPE, {\n  where: `EntityState.Name = \"${STATE}\" and LastStateChangeDate <= Today.AddDays(${-1*DAYS}) and  Project.isActive = True`,\n  select: \"id\"\n});\n\n//Move the card to the final state\nreturn entities.map(entityId => {\n  return {\n    command: \"targetprocess:MoveToState\",\n    payload: {\n      resourceType: ENTITYTYPE,\n      resourceId: entityId,\n      stateKind: \"Final\"\n    }\n  };\n});\n"
  }
]