Inherit Tags from a parent to its children
When a Story or Bug is added to a Feature, add Feature's tags to it
[
{
"type": "source:targetprocess:EntityChanged",
"entityTypes": [
"UserStory",
"Bug"
],
"modifications": {
"created": true,
"deleted": false,
"updated": [
"Feature"
]
}
},
{
"or": [
{
"and": [
{
"value": null,
"target": {
"name": "Feature",
"type": "field",
"target": {
"type": "pipelineBlockOutput"
}
},
"operator": {
"type": "exists"
}
},
{
"value": null,
"target": {
"name": "Tags",
"type": "field",
"target": {
"name": "Feature",
"type": "field",
"target": {
"type": "pipelineBlockOutput"
}
}
},
"operator": {
"type": "exists"
}
}
]
}
],
"type": "filter:Relational"
},
{
"type": "action:JavaScript",
"script": "const parent = \"Feature\";\nconst child = args.ResourceType;\n\nconst api = context.getService(\"targetprocess/api/v2\");\nconst parents = await api.queryAsync(parent, {\n select: \"{tags:TagObjects.Select(Name)}\",\n where: \"id=\" + args.Current[parent].Id\n});\nif (!parents || !parents.length) { return; }\n\nconst parentTags = parents[0].tags;\nconst childTags = args.Current.Tags ? args.Current.Tags.split(\",\") : [];\nconst tags = [...childTags , ...parentTags].join(\",\");\n\nreturn {\n command: \"targetprocess:UpdateResource\",\n payload: {\n resourceType: child,\n resourceId: args.ResourceId,\n fields: {\n Tags: tags\n }\n }\n};"
}
]
When a new tag is added for a Feature, add tags to all its Stories and Bugs
[
{
"type": "source:targetprocess:EntityChanged",
"entityTypes": [
"Feature"
],
"modifications": {
"created": false,
"deleted": false,
"updated": [
"Tags"
]
}
},
{
"or": [
{
"and": [
{
"value": null,
"target": {
"name": "Tags",
"type": "field",
"target": {
"type": "pipelineBlockOutput"
}
},
"operator": {
"type": "exists"
}
}
]
}
],
"type": "filter:Relational"
},
{
"type": "action:JavaScript",
"script": "const child = \"UserStory\";\nconst parent = args.ResourceType;\n\nconst api = context.getService(\"targetprocess/api/v2\");\nconst children = await api.queryAsync(child, {\n select: \"{id,tags:TagObjects.Select(Name)}\",\n where: `${parent}.id=${args.ResourceId}`\n});\nconst parentTags = args.Current.Tags.split(\",\");\n\nreturn children.map(item => {\n return {\n command: \"targetprocess:UpdateResource\",\n payload: {\n resourceType: child,\n resourceId: item.id,\n fields: {\n Tags: [...item.tags, ...parentTags].join(\",\")\n }\n }\n };\n});"
},
{
"type": "action:JavaScript",
"script": "const child = \"Bug\";\nconst parent = args.ResourceType;\n\nconst api = context.getService(\"targetprocess/api/v2\");\nconst children = await api.queryAsync(child, {\n select: \"{id,tags:TagObjects.Select(Name)}\",\n where: `${parent}.id=${args.ResourceId}`\n});\nconst parentTags = args.Current.Tags.split(\",\");\n\nreturn children.map(item => {\n return {\n command: \"targetprocess:UpdateResource\",\n payload: {\n resourceType: child,\n resourceId: item.id,\n fields: {\n Tags: [...item.tags, ...parentTags].join(\",\")\n }\n }\n };\n});"
}
]
Updated over 5 years ago