Apply several templates

📘

How to apply this rule?

When a template value is selected then accordingly stories and tasks are created with teams assigned automatically.

📘

Note

Please be sure to update the Team ID in the rule. And also be sure to assign the team to the Project before using the rule.

748 970
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "feature"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": false
    }
  },
  {
    "type": "filter:Relational",
    "or": [
      {
        "and": [
          {
            "target": {
              "type": "field",
              "name": "Template",
              "target": {
                "type": "pipelineBlockOutput"
              }
            },
            "value": null,
            "operator": {
              "type": "exists"
            }
          }
        ]
      }
    ]
  },
  {
    "type": "action:JavaScript",
    "script": "let stories = [];\n\nswitch (args.Current.Template) {\n\n  case \"Tech\":\n    stories = [\n      { name: \"US1\", teams: [2718], descirption: \"Test\", tasks: [\"T1\", \"T2\"] },\n      { name: \"US2\", teams: [3122], descirption: \"Test\", tasks: [\"T1\", \"T2\", \"T3\"] }\n    ]\n    break;\n\n  case \"Compliance\":\n    stories = [\n      { name: \"US3\", teams: [123, 321], descirption: \"Test\", tasks: [\"T1\", \"T2\"] },\n      { name: \"US4\", teams: [123, 321], descirption: \"Test\", tasks: [\"T1\"] }\n    ]\n    break;\n\n  case \"New Functionality\":\n    stories = [\n      { name: \"US5\", teams: [123, 321], descirption: \"Test\", tasks: [\"T1\", \"T2\"] },\n    ]\n    break;\n}\n\nreturn stories.map(story => {\n  let teams = story.teams.map(teamId => {\n    return { Team: { Id: teamId } }\n  });\n  return {\n    command: \"targetprocess:CreateResource\",\n    payload: {\n      resourceType: \"UserStory\",\n      fields: {\n        Project: { Id: args.Current.Project.Id },\n        Feature: { Id: args.Current.Id },\n        Name: story.name,\n        Description: story.description,\n        AssignedTeams: { items: teams },\n        Tasks: {\n          items: story.tasks.map(taskName => {\n            return {\n              Project: { Id: args.Current.Project.Id },\n              Name: taskName,\n              AssignedTeams: { items: teams }\n            }\n          })\n        },\n      }\n    }\n  }\n});"
  }
]