Set Found In Release/Team Iteration fields for Bugs

📘

How to apply this rule?

🚧

There are no native fields Found In Release or Team Iteration for Bugs.
The fields we're using in those rules are custom fields of a type Targetprocess Entity.

785785

Set Found In Release field for new Bugs to the Current Release

909909
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "bug"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": false
    }
  },
  {
    "type": "filter:Relational",
    "or": [
      {
        "and": [
          {
            "target": {
              "type": "field",
              "name": "Found in Release",
              "target": {
                "type": "pipelineBlockOutput"
              }
            },
            "value": null,
            "operator": {
              "type": "not exists"
            }
          }
        ]
      }
    ]
  },
  {
    "type": "action:JavaScript",
    "script": "const project = args.Current.Project;\n\nconst api = context.getService(\"targetprocess/api/v2\");\nconst releases = await api.queryAsync(\"Releases\", {\n  select: \"id\",\n  where: \"IsCurrent=true and Project.Id==\" + project.Id\n});\nif (!releases || !releases.length) {\n  console.log(`There is no current Release for the Project #${project.Id} ${project.Name}`);\n  return;\n};\n\nreturn {\n  command: \"targetprocess:UpdateResource\",\n  payload: {\n    resourceType: args.ResourceType,\n    resourceId: args.ResourceId,\n    fields: {\n      \"Found in Release\": releases[0]\n    }\n  }\n};"
  }
]

Set Found In Team Iteration field for new Bugs to the Current Team Iteration

909909
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "teamassignment"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": false
    }
  },
  {
    "or": [
      {
        "and": [
          {
            "target": {
              "type": "field",
              "name": "Name",
              "target": {
                "type": "field",
                "name": "EntityType",
                "target": {
                  "type": "field",
                  "name": "Assignable",
                  "target": {
                    "type": "pipelineBlockOutput"
                  }
                }
              }
            },
            "value": {
              "type": "constant",
              "value": "Bug"
            },
            "operator": {
              "type": "is"
            }
          },
          {
            "target": {
              "type": "field",
              "name": "Found in Team Iteration",
              "target": {
                "type": "field",
                "name": "Assignable",
                "target": {
                  "type": "pipelineBlockOutput"
                }
              }
            },
            "value": null,
            "operator": {
              "type": "not exists"
            }
          }
        ]
      }
    ],
    "type": "filter:Relational"
  },
  {
    "type": "action:JavaScript",
    "script": "const team = args.Current.Team;\r\n\r\nconst api = context.getService(\"targetprocess/api/v2\");\r\nconst iterations = await api.queryAsync(\"TeamIterations\", {\r\n  select: \"id\",\r\n  where: \"IsCurrent=true and Team.id=\" + team.Id\r\n});\r\nif (!iterations || !iterations.length) {\r\n  console.log(`There is no current Team Iteration for the Team #${team.Id} ${team.Name}`);\r\n  return;\r\n};\r\n\r\nreturn {\r\n  command: \"targetprocess:UpdateResource\",\r\n  payload: {\r\n    resourceType: \"Bug\",\r\n    resourceId: args.Current.Assignable.Id,\r\n    fields: {\r\n      \"Found in Team Iteration\": iterations[0]\r\n    }\r\n  }\r\n};"
  }
]