Assign the people working on a parent to a newly created child

📘

How to apply this rule?

Assign the people working on a User Story to a newly created Task

956
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Task"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": false
    }
  },
  {
    "type": "action:JavaScript",
    "script": "const taskId = args.ResourceId;\nconst userStoryId = args.Current.UserStory.Id;\n\n// get the list of userstory's assignments\nconst api = context.getService(\"targetprocess/api/v2\");\nconst assignments = await api.queryAsync(\"assignment\", {\n  select: \"{ roleId: role.id, userId: generalUser.id }\",\n  where: \"assignable.id = \" + userStoryId\n});\n\n// create assignments for task\nreturn assignments.map(assignment => ({\n  command: \"targetprocess:CreateResource\",\n  payload: {\n    resourceType: \"Assignment\",\n    fields: {\n      Assignable: { Id: taskId },\n      GeneralUser: { Id: assignment.userId },\n      Role: { Id: assignment.roleId }\n    }\n  }\n}));"
  }
]

Assign the people working on a User Story to a newly created Bug

1148
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Bug"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": false
    }
  },
  {
    "type": "action:JavaScript",
    "script": "const userStoryId = args.Current.UserStory.Id;\n\n// get the list of userstory's assignments\nconst api = context.getService(\"targetprocess/api/v2\");\nconst assignments = await api.queryAsync(\"assignment\", {\n  select: \"{ roleId: role.id, userId: generalUser.id }\",\n  where: \"assignable.id = \" + userStoryId\n});\n\n// create assignments for the bug\nreturn assignments.map(assignment => ({\n  command: \"targetprocess:CreateResource\",\n  payload: {\n    resourceType: \"Assignment\",\n    fields: {\n      Assignable: { Id: args.ResourceId },\n      GeneralUser: { Id: assignment.userId },\n      Role: { Id: assignment.roleId }\n    }\n  }\n}));"
  }
]

Assign the people working on a Feature to a newly created User Story

1342
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "UserStory"
    ],
    "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 userStoryId = args.ResourceId;\nconst featureId = args.Current.Feature.Id;\nconst projectId = args.Current.Project.Id;\n\n// get the list of feature's and user story's assignments\nconst api = context.getService(\"targetprocess/api/v2\");\nconst assignments = await api.queryAsync(\"assignment\", {\n  select: \"{ assignableId: assignable.id, roleId: role.id, userId: generalUser.id }\",\n  where: `assignable.id in [${userStoryId}, ${featureId}]`\n});\n\n//get the list of available Roles for User Story Assignments\nconst roleIds = await api.queryAsync(\"RoleEntityTypeProcessSetting\", {\n  select: \"role.id\",\n  where: `entityType.name = \"userStory\" and process.projects.count(id = ${projectId}) > 0 and CanBeAssigned = True`,\n  result: \"distinct\"\n});\n\n// user story assignments only\nconst userStoryAssignments = assignments.filter(assignment => assignment.assignableId === userStoryId);\n\n// feature assignments only\nconst featureAssignments = assignments.filter(assignment => assignment.assignableId === featureId);\n\n// helper function that checks if user is assigned to user story in particular role\nconst isUserAssignedToUserStory =\n  assignment => userStoryAssignments.some(userStoryAssignment =>\n    userStoryAssignment.userId === assignment.userId &&\n    userStoryAssignment.roleId === assignment.roleId);\n\n// helper function that checks if the role exists in user story workflow\nconst isRoleAvailable =\n  assignment => roleIds.some(roleId => assignment.roleId === roleId);\n\n// feature assignments that should be reflected for user story\nconst filteredAssignments = featureAssignments.filter(assignment =>\n  isRoleAvailable(assignment) && !isUserAssignedToUserStory(assignment));\n\n// create user story assignments\nreturn filteredAssignments.map(assignment => ({\n  command: \"targetprocess:CreateResource\",\n  payload: {\n    resourceType: \"Assignment\",\n    fields: {\n      Assignable: { Id: userStoryId },\n      GeneralUser: { Id: assignment.userId },\n      Role: { Id: assignment.roleId }\n    }\n  }\n}));"
  }
]

Assign the people working on an Epic to a newly created Feature

1369
[
  {
    "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:JavaScript",
    "script": "const featureId = args.ResourceId;\nconst epicId = args.Current.Epic.Id;\nconst projectId = args.Current.Project.Id;\n\n// get the list of epic's and feature's assignments\nconst api = context.getService(\"targetprocess/api/v2\");\nconst assignments = await api.queryAsync(\"assignment\", {\n  select: \"{ assignableId: assignable.id, roleId: role.id, userId: generalUser.id }\",\n  where: `assignable.id in [${featureId}, ${epicId}]`\n});\n\n//get the list of available Roles for Feature Assignments\nconst roleIds = await api.queryAsync(\"RoleEntityTypeProcessSetting\", {\n  select: \"role.id\",\n  where: `entityType.name = \"feature\" and process.projects.count(id = ${projectId}) > 0 and CanBeAssigned = True`,\n  result: \"distinct\"\n});\n\n// feature assignments only\nconst featureAssignments = assignments.filter(assignment => assignment.assignableId === featureId);\n\n// epic assignments only\nconst epicAssignments = assignments.filter(assignment => assignment.assignableId === epicId);\n\n// helper function that checks if user is assigned to feature in particular role\nconst isUserAssignedToFeature =\n  assignment => featureAssignments.some(featureAssignment =>\n    featureAssignment.userId === assignment.userId &&\n    featureAssignment.roleId === assignment.roleId);\n\n// helper function that checks if the role exists in feature workflow\nconst isRoleAvailable =\n  assignment => roleIds.some(roleId => assignment.roleId === roleId);\n\n// epic assignments that should be reflected for feature\nconst filteredAssignments = epicAssignments.filter(assignment =>\n  isRoleAvailable(assignment) && !isUserAssignedToFeature(assignment));\n\n// create feature assignments\nreturn filteredAssignments.map(assignment => ({\n  command: \"targetprocess:CreateResource\",\n  payload: {\n    resourceType: \"Assignment\",\n    fields: {\n      Assignable: { Id: featureId },\n      GeneralUser: { Id: assignment.userId },\n      Role: { Id: assignment.roleId }\n    }\n  }\n}));"
  }
]

Assign the people working on a Portfolio Epic to a newly created Epic

1324
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Epic"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": [
        "PortfolioEpic"
      ]
    }
  },
  {
    "or": [
      {
        "and": [
          {
            "value": null,
            "target": {
              "name": "PortfolioEpic",
              "type": "field",
              "target": {
                "type": "pipelineBlockOutput"
              }
            },
            "operator": {
              "type": "exists"
            }
          }
        ]
      }
    ],
    "type": "filter:Relational"
  },
  {
    "type": "action:JavaScript",
    "script": "const epicId = args.ResourceId;\nconst portfolioEpicId = args.Current.PortfolioEpic.Id;\nconst projectId = args.Current.Project.Id;\n\n// get the list of portfolio epic's and epic's assignments\nconst api = context.getService(\"targetprocess/api/v2\");\nconst assignments = await api.queryAsync(\"assignment\", {\n  select: \"{ assignableId: assignable.id, roleId: role.id, userId: generalUser.id }\",\n  where: `assignable.id in [${epicId}, ${portfolioEpicId}]`\n});\n\n//get the list of available Roles for Epics Assignments\nconst roleIds = await api.queryAsync(\"RoleEntityTypeProcessSetting\", {\n  select: \"role.id\",\n  where: `entityType.name = \"epic\" and process.projects.count(id = ${projectId}) > 0 and CanBeAssigned = True`,\n  result: \"distinct\"\n});\n\n// epic assignments only\nconst epicAssignments = assignments.filter(assignment => assignment.assignableId === epicId);\n\n// portfolio epic assignments only\nconst portfolioEpicAssignments = assignments.filter(assignment => assignment.assignableId === portfolioEpicId);\n\n// helper function that checks if user is assigned to epic in particular role\nconst isUserAssignedToEpic =\n  assignment => epicAssignments.some(epicAssignment =>\n    epicAssignment.userId === assignment.userId &&\n    epicAssignment.roleId === assignment.roleId);\n\n// helper function that checks if the role exists in epic workflow\nconst isRoleAvailable =\n  assignment => roleIds.some(roleId => assignment.roleId === roleId);\n\n// portfolio epic assignments that should be reflected for epic\nconst filteredAssignments = portfolioEpicAssignments.filter(assignment =>\n  isRoleAvailable(assignment) && !isUserAssignedToEpic(assignment));\n\n// create epic assignments\nreturn filteredAssignments.map(assignment => ({\n  command: \"targetprocess:CreateResource\",\n  payload: {\n    resourceType: \"Assignment\",\n    fields: {\n      Assignable: { Id: epicId },\n      GeneralUser: { Id: assignment.userId },\n      Role: { Id: assignment.roleId }\n    }\n  }\n}));"
  }
]