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

πŸ“˜

How to apply this rule?

Inherit Team Iteration from User Stories to Feature

[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "UserStory"
    ],
    "modifications": {
      "created": true,
      "deleted": true,
      "updated": [
        "TeamIteration",
        "Feature"
      ]
    }
  },
  {
    "or": [
      {
        "and": [
          {
            "value": null,
            "target": {
              "name": "Feature",
              "type": "field",
              "target": {
                "type": "pipelineBlockOutput"
              }
            },
            "operator": {
              "type": "exists"
            }
          }
        ]
      },
      {
        "and": [
          {
            "value": {
              "type": "pipelineBlockOutput"
            },
            "target": {
              "name": "Feature",
              "type": "field",
              "target": {
                "name": "Previous",
                "type": "field",
                "target": {
                  "type": "pipelineBlockOutput"
                }
              }
            },
            "operator": {
              "type": "exists"
            }
          }
        ]
      }
    ],
    "type": "filter:Relational"
  },
  {
    "type": "action:JavaScript",
    "script": "const parent = \"Feature\";\nconst children = \"UserStories\";\nconst timebox = \"TeamIteration\";\n\nconst parentIds = [];\nif (args.Current[parent]) { parentIds.push(args.Current[parent].Id); }\nif (args.Previous && args.Previous[parent]) { parentIds.push(args.Previous[parent].Id); }\n\nconst api = context.getService(\"targetprocess/api/v2\");\nconst parents = await api.queryAsync(parent, {\n  select: `{id,currentId:${timebox}.Id,targetId:${children}.OrderByDescending(${timebox}.EndDate).First().${timebox}.Id}`,\n  where: `id in [${parentIds.join(',')}]`\n});\n\nreturn parents\n  .filter(entity => entity.currentId !== entity.targetId)\n  .map(entity => {\n    return {\n      command: \"targetprocess:UpdateResource\",\n      payload: {\n        resourceType: parent,\n        resourceId: entity.id,\n        fields: {\n          [timebox]: entity.targetId ? { Id: entity.targetId } : null\n        }\n      }\n    }\n  });"
  }
]