Inherit Team Iteration/Release/Iteration from parent to its children

📘

How to apply this rule?

Assign Feature's Team Iteration to its User Stories and Bugs

📘

This rule can be adjusted for Release/Iteration use cases. In order to do that please replace "TeamIteration" word in lines 1,2 and 18 of Javascript code with "Release" or "Iteration" correspondingly

1959

JavaScript for action:

const scopeId = args.Current.TeamIteration ?
  { Id: args.Current.TeamIteration.Id } :
  null;

const api = context.getService("targetprocess/api/v2");
const assignables = await api.queryAsync("Assignable", {
  select: 'id',
  where: "feature.id = " + args.Current.Id
});

return assignables.map(id => {
  return {
    command: "targetprocess:UpdateResource",
    payload: {
      resourceType: "Assignable",
      resourceId: id,
      fields: {
        TeamIteration: scopeId
      }
    }
  }
});

Rule config:

[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Feature"
    ],
    "modifications": {
      "created": false,
      "deleted": false,
      "updated": [
        "TeamIteration"
      ]
    }
  },
  {
    "or": [],
    "type": "filter:Relational"
  },
  {
    "type": "action:JavaScript",
    "script": "const teamIteration = args.Current.TeamIteration ?\r\n  { Id: args.Current.TeamIteration.Id } :\r\n  null;\r\n\r\nconst api = context.getService(\"targetprocess/api/v2\");\r\nconst assignables = await api.queryAsync(\"Assignable\", {\r\n  select: 'id',\r\n  where: \"feature.id = \" + args.Current.Id\r\n});\r\n\r\nreturn assignables.map(id => {\r\n  return {\r\n    command: \"targetprocess:UpdateResource\",\r\n    payload: {\r\n      resourceType: \"Assignable\",\r\n      resourceId: id,\r\n      fields: {\r\n        TeamIteration: teamIteration\r\n      }\r\n    }\r\n  }\r\n});\r\n"
  }
]

Update Team Iteration of User Story/Bug when they are added to Feature

📘

This rule can be adjusted for Release/Iteration use cases. In order to do that please replace "TeamIteration" word in lines 3,14 of Javascript code with "Release" or "Iteration" correspondingly

1922

JavaScript for action:

const api = context.getService("targetprocess/api/v2");
const features = await api.queryAsync("Feature", {
  select: "TeamIteration.Id",
  where: "Id=" + args.Changed.Feature.Id
});
const id = features[0];

return {
  command: "targetprocess:UpdateResource",
  payload: {
    resourceType: "Assignable",
    resourceId: args.ResourceId,
    fields: {
      TeamIteration: { Id: id },
    }
  }
};

Rule config:

[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "UserStory",
      "Bug"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": [
        "Feature"
      ]
    }
  },
  {
    "or": [
      {
        "and": [
          {
            "value": null,
            "target": {
              "name": "Feature",
              "type": "field",
              "target": {
                "type": "pipelineBlockOutput"
              }
            },
            "operator": {
              "type": "exists"
            }
          }
        ]
      }
    ],
    "type": "filter:Relational"
  },
  {
    "type": "action:JavaScript",
    "script": "const api = context.getService(\"targetprocess/api/v2\");\nconst features = await api.queryAsync(\"Feature\", {\n  select: \"TeamIteration.Id\",\n  where: \"Id=\" + args.Changed.Feature.Id\n});\nconst id = features[0];\n\nreturn {\n  command: \"targetprocess:UpdateResource\",\n  payload: {\n    resourceType: \"Assignable\",\n    resourceId: args.ResourceId,\n    fields: {\n      TeamIteration: { Id: id },\n    }\n  }\n};"
  }
]