Hi,
I'm currently exploring the capabilities of automation for Jira to have a hierarchy alignemnt on Components fileds of a group Epic-Story-subtask.
I'm already able to copy components from a parent. Also to add new components when the parent changes (or to replace them).
My current problem is about how to delete a specific component value from the list of compontents of an issue.
The practical example is the following one. But, currently, I'm still not able to delete a specified component.
step1) sub-tasks and stories already inherited Epic components (maybe appending to any already existing)
step2) one component is deleted from a parent issue (let's say the epic)
step3) the same component SHOULD be deleted from the childrens (let's say at lest from the stories under that epic)
I was trying to use smart values/advanced rules/variables to solve step3) but nothing seems to fit my needs.
Could anyone help me?
thank you in advance for the help.
You can remove a component using automation with custom fields and the list, string, advanced JSON edit, and create variable functions. It is a bit messy, so if you want the details of how to try this, please let me know.
Summary of how this works: concatenate the component values into Json, remove the target value, and use the remaining Json to update the component list.
Best regards,
Bill
Hi Bill,
yes it is exactly what i wanted to try, but something is not totally clear to me.
I should to use "additional fields" box into a "edit issue fields". But I never worked with Jsons. I mean, never programming them.
It will be really helpfull to read how to proceed. Could you kindly try to explain me? actually I'm trying to understand recursive concatenation with smart values.
I'm already able to extract the list of the components, separated by comma, before change and after.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is the information for how I removed a component. Please consider adding logging to see what is happening during the processing.
'{{issue.components.name.split(",").get(2)}}'
{{#issue.components}}{ 'name': '{{name}}'} , {{/}}
{{firstJson.remove(issue.WorkingComponent).remove("{ 'name': } , ").substringBeforeLast(",").replace("'","\"")}}
{
"fields": { "components" : [ {{finalJson}} ] }
}
Here is the documentation on advanced field editing with JSON, the string functions, and the list functions I used:
https://support.atlassian.com/jira-software-cloud/docs/advanced-field-editing-json/
https://support.atlassian.com/jira-software-cloud/docs/smart-values-text-fields/
https://support.atlassian.com/jira-software-cloud/docs/smart-values-lists/
Best regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ciao Bill,
Many thanks for your help. I have to say that it is working!
I'm able to move modified epic components to the children now.
The next step will be to manage any additional component at children level (not present into fathers) But i should have enough info to update also in this direction. Just need the time to think about :)
Best Regards,
Michele
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy I am wondering if there is some substitute to "create variable" in Jira data center. The question here is that we are struggling to delete one component/s from Jira issue and we got stuck and not moving forward. Is there any other approach that we can apply to achieve on data center.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Alok Juneja
First thing, I am using Jira Cloud and so do not have Server/Data Center to test this...
I can think of two ways:
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy Thanks for tips. The option 1 worked on Jira data center. I managed to create custom field and once work is done I deleted their contents.
I get interested into "Entity Property", since I have never worked with it before. I am wondering if you have some tips about it in case I want to proceed with "Entity property" then how can I move forward. This is mostly from learning perspective.
Regarding option 2, I am experimenting on it. In case I find some breakthrough, I post it here for readers who land on this page in future.
Once again thanks @Bill Sheboy for the tip.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am glad to learn that helped.
You may set entity properties at various levels, although the automation rules do not support set/read of them all directly, as described here:
https://confluence.atlassian.com/automation0801/jira-automation-actions-1223822666.html
For ones at other scopes (e.g., project) you would need to call the REST API with a web request. For your scenario, I do not believe you would need to do that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In JSON format in a modify issue use this syntax:
{
"update": {
"components": [{
"remove": {"name": "Component_Name_To_Remove"}
}]
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great solution from @Bill Sheboy, but I think it is possible to remove components without creating a custom field. Interesting question @Michele D'Adamo actually I had to face a similar problem.
Here is a more elaborated rule, based on my real scenario, which serves to add and remove components.
Here is the scenario:
Here is the definition of the manual rules with the corresponding entries. We use some default values for testing purposes:
Here is the entire automation rule:
Let's see some specific settings:
{{replaceRegEx}}. This is what we use to add the project prefix to the input issues keys:
{{project.key}}-$1
Clean and standardize userInputs.keys and set the variable {{key}}s:
{{userInputs.keys.trim().replaceAll("\\s*['\"]+\\s*","").replaceAll("\\s*[,;]+\\s*$","").replaceAll("\\s+", " ").replaceAll("\\s?[,;]+\\s?", ",").replaceAll("\\s?[\-_]+\\s?", "-").replaceAll("(?:[A-Z]+-)*([0-9]+)",replaceRegEx)}}
The last replaceAll is used for extracting the numbers adding the project key as a prefix and adding the dash. It works in both cases, then the issue numbers are provided (1,2,3, etc.), or the issue keys (XYZ-1,XYZ-2,XYZ-3, etc.). Since as per the documentation of replaceAll function only $1 can be used, the first group is not captured (?:).
Similarly, we clean and process the user inputs: addCom, and remCom, as follows defining the follow smart values:
{{addCom}}:
{{userInputs.addComp.trim().replaceAll("\\s*['\"]+\\s*","").replaceAll("\\s*[,;]+\\s*$","").replaceAll("\\s+", " ").replaceAll("\\s?[,;]+\\s?", ",")}}
{{remCom}}:
{{userInputs.remComp.trim().replaceAll("\\s*['\"]+\\s*","").replaceAll("\\s*[,;]+\\s*$","").replaceAll("\\s+", " ").replaceAll("\\s?[,;]+\\s?", ",")}}
Look up issues. In the case case issue keys are not provided via input, then we use this {{lookupissue}} smart variable, as issue keys, for all issues that belong to the epic:
"Epic Link" = {{issue.key}}
{{epicIssues}}, is the string representation of all issues within the epic delimited by a comma:
{{#lookupIssues}}{{.}}{{^last}},{{/}}{{/}}
We define again the smart value {{keys}} (yes it is possible, you can define a variable with the same name more than once). Since smart values don't support if-else, it is constructed as follows:
{{#if(not(keys.isEmpty()))}}{{keys}}{{/}}{{#if(keys.isEmpty())}}{{epicIssues}}{{/}}
Idea taken from here: answer to this question Ternary operator (or if/else) with smart values from @Chad Waldman
Now we have all the input information to edit related issues.
If all match condition checks one of the addCom or remCom is provided. We check the length of each string. Since The if condition can only allow all matches or any match, to mix and or condition, we use the length of both inputs is greater than zero. The condition that {{keys}} contains the project key is just an additional check for the input keys, not going further if the issue keys are not specific to the current project or any failure in processing information.
The smart variable {{qq}} just has a single quote ("), we use it for appending the string delimiter.
We use Branch rule/related issues and the type of related issue is specified through a JQL:
key in ({{keys}})
The variable {{issueComps}}, has all the components of the issue triggered in the branch delimited by a comma:
{{#issue.components.name}}{{.}},{{/}}
The variable {{issueCompsPlusAddCom}} has the existing components plus the components to add:
{{issueComps.concat(addComp)}}
{{issueComps}} has a trailing comma, so we don't need to add it building {{issueCompsPlusAddCom}}.
Notice, when we set the components Jira doesn't take into account repeated component names, so we don't need to exclude duplicates.
To remove the list of remCom from the previous variable, we use a regular expression {{orCondRegex}}:
({{remComp.replace(",","|")}}),?
Replacing the "," with "|" we would get an or regex condition. The last portion is to remove the trailing comma in case it is present.
The variable {{comps}}:
{{issueCompsPlusAddComp.replaceAll(orCondRegex,"").replaceAll("(,+)", ",")}}
Removes all the remComp values from issueCompsPlusAddComp and removes any duplicated comma as a result of the deletion.
The variable {{compsCsv}} converts {{comps}} variable with CSV delimited by string quotation (").
Now we have all the information we need to build the jsonComps variable:
{{#compsCsv.split(",")}}{ "name" : {{.}}{{^last}}} , {{/}}{{/}}}
Spit is used to generate a list, then we iterate over all elements adding the prefix "name : " and adding as a suffix "}," except for the last one.
Finally, using Advanced Issue Edit, we build the final JSON file as follows:
{
"fields" : {
"components" : [ {{jsonComps}} ]
}
}
We included some log instructions to trace the information. If you don't want to execute the last command and just debug the entire process without modifying the issue, just add a false condition before to visualize the information in the log without making the changes.
Even for components the Jira REST API JSON file allows add/remove actions, such actions can be applied for single values only, not for modifying an array of components to add or remove.
Here is the log output:
The branch runs for two issues, to the log trace concatenates the information for each issue.
I hope it helps,
David
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Michele D'Adamo
Thank you for reaching out.
Indeed, Jira automation does not have a function to remove a component of a child issue (Stories, Sub-task, etc) when it gets removed in the parent issue (Epic or Parent task). We have the following feature request to get this function implemented on the rule triggers, so you would be able to use the Smart values to properly reference it in the rule actions:
Trigger rule when value is added/removed from multi-select type field
You can keep an eye on that feature request to check any updates.
If the child issues should have the exact same components as the parent issues, a possible solution would be to completely override the components of the child issues with the ones selected/removed in the Parent issue:
For more details, you can check the section "Add values to multi-select fields" of the documentation below:
Let us know if you have any questions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.