Inherit Portfolio Epic from Epic to its Features

📘

How to apply this rule?

Inherit Portfolio Epic when Feature is added to an Epic

1140
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Feature"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": [
        "Epic"
      ]
    }
  },
  {
    "or": [
      {
        "and": [
          {
            "value": null,
            "target": {
              "name": "Epic",
              "type": "field",
              "target": {
                "type": "pipelineBlockOutput"
              }
            },
            "operator": {
              "type": "exists"
            }
          }
        ]
      }
    ],
    "type": "filter:Relational"
  },
  {
    "type": "action:targetprocess:UpdateEntity",
    "fields": {
      "PortfolioEpic": {
        "name": "PortfolioEpic",
        "type": "field",
        "target": {
          "name": "Epic",
          "type": "field",
          "target": {
            "type": "pipelineBlockOutput"
          }
        }
      }
    },
    "target": {
      "type": "pipelineBlockOutput",
      "blockAlias": "ui:source"
    }
  }
]

When Portfolio Epic for an Epic is changed, change it for all Epic's Features

1153
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Epic"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": [
        "PortfolioEpic"
      ]
    }
  },
  {
    "type": "action:JavaScript",
    "script": "//get the list of all Features\nconst api = context.getService(\"targetprocess/api/v2\");\nconst featureIds = await api.queryAsync(\"Feature\", {\n  \"select\": \"id\",\n  \"where\": \"epic.id =\" + args.ResourceId\n});\nif (!featureIds || !featureIds.length) { return; }\n\n//set Portfolio Epic for all Features\nconst pe = args.Current.PortfolioEpic ? { Id: args.Current.PortfolioEpic.Id } : null;\nreturn featureIds.map(value => ({\n  command: \"targetprocess:UpdateResource\",\n  payload: {\n    resourceId: value,\n    resourceType: \"Feature\",\n    fields: {\n      PortfolioEpic: pe\n    }\n  }\n}));"
  }
]