Reschedule work items in a Release / Iteration / Team Iteration

🚧

The number of entities that can be updated is limited. See the detailed information in the article Limits and Timeouts

📘

How to apply this rule?
How to set Planned Dates based on Iteration/Release/Team Iteration dates?

Reschedule work items in a Release

909
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Release"
    ],
    "modifications": {
      "created": false,
      "deleted": false,
      "updated": [
        "StartDate"
      ]
    }
  },
  {
    "type": "action:JavaScript",
    "script": "const MILLISECONDS_IN_DAY = 1000 * 3600 * 24;\n\nfunction differenceInDays(dateLeft, dateRight) {\n  dateLeft = new Date(dateLeft);\n  dateRight = new Date(dateRight);\n  return Math.round((dateLeft.getTime() - dateRight.getTime()) / MILLISECONDS_IN_DAY);\n}\n\nfunction addDays(date, days) {\n  const result = new Date(date);\n  result.setDate(result.getDate() + days);\n  return result;\n}\n\nconst api = context.getService(\"targetprocess/api/v2\");\nconst assignables = await api.queryAsync(\"Assignable\", {\n  select: \"{ id, plannedStartDate, plannedEndDate, entityType:entityType.Name }\",\n  where: \"release.id = \" + args.ResourceId + \" and (plannedStartDate != null or plannedEndDate != null)\"\n});\n\nconst shift = differenceInDays(args.Current.StartDate, args.Previous.StartDate);\n\nreturn assignables.map(assignable => {\n  const { id, entityType, plannedStartDate, plannedEndDate } = assignable;\n  const start = plannedStartDate ? addDays(plannedStartDate, shift) : undefined;\n  const end = plannedEndDate ? addDays(plannedEndDate, shift) : undefined;\n\n  return {\n    command: \"targetprocess:UpdateResource\",\n    payload: {\n      resourceId: id,\n      resourceType: entityType,\n      fields: {\n        PlannedStartDate: start,\n        PlannedEndDate: end\n      }\n    }\n  }\n});"
  }
]

Reschedule work items in an Iteration

The filter by Project.Name is optional.

918
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Iteration"
    ],
    "modifications": {
      "created": false,
      "deleted": false,
      "updated": [
        "StartDate"
      ]
    }
  },
  {
    "type": "filter:Relational",
    "or": [
      {
        "and": [
          {
            "target": {
              "type": "field",
              "name": "Name",
              "target": {
                "type": "field",
                "name": "Project",
                "target": {
                  "type": "pipelineBlockOutput"
                }
              }
            },
            "value": {
              "type": "constant",
              "value": "Custom Development"
            },
            "operator": {
              "type": "is"
            }
          }
        ]
      }
    ]
  },
  {
    "type": "action:JavaScript",
    "script": "const MILLISECONDS_IN_DAY = 1000 * 3600 * 24;\n\nfunction differenceInDays(dateLeft, dateRight) {\n  dateLeft = new Date(dateLeft);\n  dateRight = new Date(dateRight);\n  return Math.round((dateLeft.getTime() - dateRight.getTime()) / MILLISECONDS_IN_DAY);\n}\n\nfunction addDays(date, days) {\n  const result = new Date(date);\n  result.setDate(result.getDate() + days);\n  return result;\n}\n\nconst api = context.getService(\"targetprocess/api/v2\");\nconst assignables = await api.queryAsync(\"Assignable\", {\n  select: \"{ id, plannedStartDate, plannedEndDate, entityType:entityType.Name }\",\n  where: \"iteration.id = \" + args.ResourceId + \" and (plannedStartDate != null or plannedEndDate != null)\"\n});\n\nconst shift = differenceInDays(args.Current.StartDate, args.Previous.StartDate);\n\nreturn assignables.map(assignable => {\n  const { id, entityType, plannedStartDate, plannedEndDate } = assignable;\n  const start = plannedStartDate ? addDays(plannedStartDate, shift) : undefined;\n  const end = plannedEndDate ? addDays(plannedEndDate, shift) : undefined;\n\n  return {\n    command: \"targetprocess:UpdateResource\",\n    payload: {\n      resourceId: id,\n      resourceType: entityType,\n      fields: {\n        PlannedStartDate: start,\n        PlannedEndDate: end\n      }\n    }\n  }\n});"
  }
]

Reschedule work items in a Team Iteration

The filter by Team.Name is optional.

919
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "TeamIteration"
    ],
    "modifications": {
      "created": false,
      "deleted": false,
      "updated": [
        "StartDate"
      ]
    }
  },
  {
    "or": [
      {
        "and": [
          {
            "value": {
              "type": "constant",
              "value": "Scrum Team"
            },
            "target": {
              "name": "Name",
              "type": "field",
              "target": {
                "name": "Team",
                "type": "field",
                "target": {
                  "type": "pipelineBlockOutput"
                }
              }
            },
            "operator": {
              "type": "is"
            }
          }
        ]
      }
    ],
    "type": "filter:Relational"
  },
  {
    "type": "action:JavaScript",
    "script": "const MILLISECONDS_IN_DAY = 1000 * 3600 * 24;\n\nfunction differenceInDays(dateLeft, dateRight) {\n  dateLeft = new Date(dateLeft);\n  dateRight = new Date(dateRight);\n  return Math.round((dateLeft.getTime() - dateRight.getTime()) / MILLISECONDS_IN_DAY);\n}\n\nfunction addDays(date, days) {\n  const result = new Date(date);\n  result.setDate(result.getDate() + days);\n  return result;\n}\n\nconst api = context.getService(\"targetprocess/api/v2\");\nconst assignables = await api.queryAsync(\"Assignable\", {\n  select: \"{ id, plannedStartDate, plannedEndDate, entityType:entityType.Name }\",\n  where: \"teamIteration.id = \" + args.ResourceId + \" and (plannedStartDate != null or plannedEndDate != null)\"\n});\n\nconst shift = differenceInDays(args.Current.StartDate, args.Previous.StartDate);\n\nreturn assignables.map(assignable => {\n  const { id, entityType, plannedStartDate, plannedEndDate } = assignable;\n  const start = plannedStartDate ? addDays(plannedStartDate, shift) : undefined;\n  const end = plannedEndDate ? addDays(plannedEndDate, shift) : undefined;\n\n  return {\n    command: \"targetprocess:UpdateResource\",\n    payload: {\n      resourceId: id,\n      resourceType: entityType,\n      fields: {\n        PlannedStartDate: start,\n        PlannedEndDate: end\n      }\n    }\n  }\n});"
  }
]