Create pre-defined hierarchy for new Projects

📘

How to apply this rule?

The filter by the Process is optional.

1040

JavaScript for action:

const commands = [];
const projectId = args.ResourceId;
const projectName = args.Current.Name;

commands.push({
    command: "targetprocess:CreateResource",
    payload: {
            resourceType: "Epic",
            fields: {
                Name: "Auto created epic1 for project " + projectName,
                Project: {id: projectId},
                Features: {items:[
                    {
                        Name: "Auto created feature11 for project " + projectName,
                        Project: {id: projectId},
                        UserStories: {items:[{
                            Name: "Auto created us111 for project " + projectName,
                            Project: {id: projectId}
                        }, {
                            Name: "Auto created us112 for project " + projectName,
                            Project: {id: projectId}
                        }]}
                    }, {
                        Name: "Auto created feature12 for project " + projectName,
                        Project: {id: projectId},
                        UserStories: {items:[{
                            Name: "Auto created us121 for project " + projectName,
                            Project: {id: projectId}
                        }]}
                    }
                ]}
            }
        }
});

commands.push({
    command: "targetprocess:CreateResource",
    payload: {
            resourceType: "Epic",
            fields: {
                Name: "Auto created epic2 for project " + projectName,
                Project: {id: projectId},
                Features: {items:[
                    {
                        Name: "Auto created feature21 for project " + projectName,
                        Project: {id: projectId},
                        UserStories: {items:[{
                            Name: "Auto created us211 for project " + projectName,
                            Project: {id: projectId}
                        }, {
                            Name: "Auto created us212 for project " + projectName,
                            Project: {id: projectId}
                        }]}
                    }, {
                        Name: "Auto created feature22 for project " + projectName,
                        Project: {id: projectId},
                        UserStories: {items:[{
                            Name: "Auto created us221 for project " + projectName,
                            Project: {id: projectId}
                        }]},
                    }
                ]}
            }
        }
});

return commands;

Rule config:

[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Project"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": false
    }
  },
  {
    "type": "action:JavaScript",
    "script": "const commands = [];\nconst projectId = args.ResourceId;\nconst projectName = args.Current.Name;\n\ncommands.push({\n    command: \"targetprocess:CreateResource\",\n    payload: {\n            resourceType: \"Epic\",\n            fields: {\n                Name: \"Auto created epic1 for project \" + projectName,\n                Project: {id: projectId},\n                Features: {items:[\n                    {\n                        Name: \"Auto created feature11 for project \" + projectName,\n                        Project: {id: projectId},\n                        UserStories: {items:[{\n                            Name: \"Auto created us111 for project \" + projectName,\n                            Project: {id: projectId}\n                        }, {\n                            Name: \"Auto created us112 for project \" + projectName,\n                            Project: {id: projectId}\n                        }]}\n                    }, {\n                        Name: \"Auto created feature12 for project \" + projectName,\n                        Project: {id: projectId},\n                        UserStories: {items:[{\n                            Name: \"Auto created us121 for project \" + projectName,\n                            Project: {id: projectId}\n                        }]}\n                    }\n                ]}\n            }\n        }\n});\n\ncommands.push({\n    command: \"targetprocess:CreateResource\",\n    payload: {\n            resourceType: \"Epic\",\n            fields: {\n                Name: \"Auto created epic2 for project \" + projectName,\n                Project: {id: projectId},\n                Features: {items:[\n                    {\n                        Name: \"Auto created feature21 for project \" + projectName,\n                        Project: {id: projectId},\n                        UserStories: {items:[{\n                            Name: \"Auto created us211 for project \" + projectName,\n                            Project: {id: projectId}\n                        }, {\n                            Name: \"Auto created us212 for project \" + projectName,\n                            Project: {id: projectId}\n                        }]}\n                    }, {\n                        Name: \"Auto created feature22 for project \" + projectName,\n                        Project: {id: projectId},\n                        UserStories: {items:[{\n                            Name: \"Auto created us221 for project \" + projectName,\n                            Project: {id: projectId}\n                        }]},\n                    }\n                ]}\n            }\n        }\n});\n\n\n\nreturn commands;"
  }
]