Send closed stories to Slack

📘

How to apply this rule?

In this rule we're sending ID and Name of closed User Stories, together with the names of assigned developers.

906

🚧

Warning: sample URLs!

Please make sure to replace https://hooks.slack.com/services/xxxxx/yyyyyy/zzzzzzzzztGRAKwHLfm4kw with your Slack Webhook URL and https://youraccount.tpondemand.com/ with your Targetprocess URL

[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "UserStory"
    ],
    "modifications": {
      "created": false,
      "deleted": false,
      "updated": [
        "EntityState"
      ]
    }
  },
  {
    "type": "filter:Relational",
    "or": [
      {
        "and": [
          {
            "target": {
              "type": "field",
              "name": "IsFinal",
              "target": {
                "type": "field",
                "name": "EntityState",
                "target": {
                  "type": "pipelineBlockOutput"
                }
              }
            },
            "value": null,
            "operator": {
              "type": "is true"
            }
          },
          {
            "target": {
              "type": "field",
              "name": "IsFinal",
              "target": {
                "type": "field",
                "name": "EntityState",
                "target": {
                  "type": "field",
                  "name": "Previous",
                  "target": {
                    "type": "pipelineBlockOutput"
                  }
                }
              }
            },
            "value": null,
            "operator": {
              "type": "is false"
            }
          }
        ]
      }
    ]
  },
  {
    "type": "action:JavaScript",
    "script": "const api = context.getService(\"targetprocess/api/v2\");\nconst developers = await api.queryAsync(\"Assignments\", {\n  select: \"generaluser.fullname\",\n  where: \"role.id=1 and assignable.id=\"+args.ResourceId\n});\n\n//IMPORTANT: Change the account name below\nconst link = `<https://youraccount.tpondemand.com/entity/${args.ResourceId}|${args.Current.Name}>`\n\n//IMPORTANT: Update Slack link below\nreturn {\n  command: \"SendHttpRequest\",\n  payload: {\n    url: \"https://hooks.slack.com/services/xxxxx/yyyyyy/zzzzzzzzztGRAKwHLfm4kw\",\n    body: {\n      text: `US ${link} was closed by ${args.Author.FullName}. Developers: ${developers.join(\",\") || \"none\"}`,\n      username: \"TP\",\n      icon_emoji: \":heavy_check_mark:\"\n    }\n  }\n};"
  }
]