Targetprocess

The Targetprocess Developer Hub

Welcome to the Targetprocess developer hub. Here you'll find comprehensive guides and documentation to help you start working with Targetprocess as quickly as possible and support you if you get stuck. Let's jump right in!

Docs

Follow items automatically

📘

How to apply this rule?

Add the owner as a follower

[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "UserStory",
      "Bug",
      "Task",
      "Request",
      "Feature",
      "Epic",
      "PortfolioEpic"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": [
        "Owner"
      ]
    }
  },
  {
    "type": "filter:JavaScript",
    "script": "const api = context.getService(\"targetprocess/api/v2\");\nconst followers = await api.queryAsync(\"GeneralFollowers\", {\n  result: \"count\",\n  where: `General.Id=${args.ResourceId} and User.Id=${args.Current.Owner.Id}`\n});\n\nreturn followers == 0;"
  },
  {
    "type": "action:targetprocess:CreateEntity",
    "entityType": {
      "type": "constant",
      "value": "GeneralFollower"
    },
    "fields": {
      "General": {
        "type": "field",
        "name": "Id",
        "target": {
          "type": "pipelineBlockOutput"
        }
      },
      "User": {
        "type": "field",
        "name": "Id",
        "target": {
          "type": "field",
          "name": "Owner",
          "target": {
            "type": "pipelineBlockOutput"
          }
        }
      }
    }
  }
]

Add assigned users as followers

[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Assignment"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": false
    }
  },
  {
    "type": "filter:JavaScript",
    "script": "const api = context.getService(\"targetprocess/api/v2\");\nconst followers = await api.queryAsync(\"GeneralFollowers\", {\n  result: \"count\",\n  where: `General.Id=${args.Current.Assignable.Id} and User.Id=${args.Current.GeneralUser.Id}`\n});\n\nreturn followers == 0;"
  },
  {
    "type": "action:targetprocess:CreateEntity",
    "entityType": {
      "type": "constant",
      "value": "GeneralFollower"
    },
    "fields": {
      "General": {
        "type": "field",
        "name": "Id",
        "target": {
          "type": "field",
          "name": "Assignable",
          "target": {
            "type": "pipelineBlockOutput"
          }
        }
      },
      "User": {
        "type": "field",
        "name": "Id",
        "target": {
          "type": "field",
          "name": "GeneralUser",
          "target": {
            "type": "pipelineBlockOutput"
          }
        }
      }
    }
  }
]

Remove a user from followers when they are unassigned

[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Assignment"
    ],
    "modifications": {
      "created": false,
      "deleted": true,
      "updated": false
    }
  },
  {
    "type": "filter:Relational",
    "or": [
      {
        "and": [
          {
            "target": {
              "type": "field",
              "name": "Id",
              "target": {
                "type": "field",
                "name": "Owner",
                "target": {
                  "type": "field",
                  "name": "Assignable",
                  "target": {
                    "type": "pipelineBlockOutput"
                  }
                }
              }
            },
            "value": {
              "type": "field",
              "name": "Id",
              "target": {
                "type": "field",
                "name": "GeneralUser",
                "target": {
                  "type": "pipelineBlockOutput"
                }
              }
            },
            "operator": {
              "type": "is not"
            }
          }
        ]
      }
    ]
  },
  {
    "type": "filter:JavaScript",
    "script": "const api = context.getService(\"targetprocess/api/v2\");\nconst assignments = await api.queryAsync(\"Assignment\", {\n  result: \"count\",\n  where: `Assignable.Id=${args.Current.Assignable.Id} and GeneralUser.Id=${args.Current.GeneralUser.Id}`\n});\n\nreturn assignments == 0;"
  },
  {
    "type": "action:JavaScript",
    "script": "const api = context.getService(\"targetprocess/api/v2\");\nconst follows = await api.queryAsync(\"GeneralFollower\", {\n  select: \"id\",\n  where: `General.Id=${args.Current.Assignable.Id} and User.Id=${args.Current.GeneralUser.Id}`\n});\n\nreturn follows.map(id => {\n  return {\n    command: \"targetprocess:DeleteResource\",\n    payload: {\n      resourceType: \"GeneralFollower\",\n      resourceId: id\n    }\n  };\n});"
  }
]

Add commented users as followers

[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Comment"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": false
    }
  },
  {
    "type": "filter:JavaScript",
    "script": "const api = context.getService(\"targetprocess/api/v2\");\nconst followers = await api.queryAsync(\"GeneralFollowers\", {\n  result: \"count\",\n  where: `General.Id=${args.Current.General.Id} and User.Id=${args.Current.Owner.Id}`\n});\n\nreturn followers == 0;"
  },
  {
    "type": "action:targetprocess:CreateEntity",
    "entityType": {
      "type": "constant",
      "value": "GeneralFollower"
    },
    "fields": {
      "General": {
        "type": "field",
        "name": "Id",
        "target": {
          "type": "field",
          "name": "General",
          "target": {
            "type": "pipelineBlockOutput"
          }
        }
      },
      "User": {
        "type": "field",
        "name": "Id",
        "target": {
          "type": "field",
          "name": "Owner",
          "target": {
            "type": "pipelineBlockOutput"
          }
        }
      }
    }
  }
]

Updated 2 years ago

Follow items automatically


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.