In Jira Automation, how do I add to a component, and not clear the existing value?

April_Delay November 17, 2022

I am trying to make a rule where when an issue is assigned to a specific set of users, the component field is updated to include a specific component, let's call it "kitttens". I got this automation working, however, it's replacing the values in the component field with "kittens". I want it to say "kittens" and "puppies".

2 answers

1 accepted

1 vote
Answer accepted
April_Delay November 17, 2022

Well this is embarrassing, I solved my own problem =)

 

In case anyone else needs it, the answer in the automation is edit issue-> components-> "kittens" and "copy from issue"

John Funk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 17, 2022

Glad you found it! Sorry we couldn't get to you before then.  ;-)

Chad Vernon January 22, 2023

How do you enter a component in addition to Copy Components from Current Issue? My UI only allows me to select Copy Components from Current Issue and I can't enter anything else.

 

Screenshot 2023-01-22 231048.png

Karen Corbeill February 8, 2023

I am also looking for the answer to this. I want to add to existing values in the Components field. Right now my options are only Set or Copy. I would love the options to be the same as it is with Labels where you can specify Set, Add/Remove, or Copy.

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 8, 2023

Hi @Chad Vernon and @Karen Corbeill 

It appears you want to add additional components, rather than replace or copy them.

To do that, you would use the advanced edit with JSON options.  Unfortunately I do not believe you can add just one component value with JSON, like with Labels.  Instead you must capture all the existing ones first, add the additional one, and then set them all at once.

Here is a rule which can do that for Jira Cloud.  The same can be done with Server/Data Center versions by eliminating the created variables and doing this in one step.

  • trigger: select your trigger which provides the issue.  Let's assume Manual trigger for now.
  • action: create a variable for the current components as JSON
    • variable name: varCurrentComponents
    • smart value: {{#issue.components}}{ "name": "{{name}}"} {{^last}}, {{/}}{{/}}
  • action: create another variable which adds the new component
    • variable name: varNewComponents
    • smart value: {{varCurrentComponents}} , { "name": "My Added Component"}
  • action: edit issue, selecting the More Options section for advanced edit
{
"fields": {
"components" : [ {{varNewComponents}} ]
}
}

 

How this works...

  1. Gather the current components, and iterate over them as a list of values, and put them into a JSON format
  2. Add the new component, also in JSON format
  3. Finally set the components field to replace the values

 

Please try that and let the community know if you need further help with this.

Kind regards,
Bill

Like # people like this
Karen Corbeill February 9, 2023

This looks great! I'll have to give it a try. Thank you so much!

Like # people like this
Chad Vernon April 3, 2023

How do you deal with the case where varCurrentComponents is empty so the resulting json in the last action is invalid?

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 3, 2023

Hi @Chad Vernon 

You can use the conditional handling to test for the empty value, and only include/use the JSON when needed.  This could also be done with a rule condition.

Kind regards,
Bill

Chad Vernon April 3, 2023

I ended up using:

{"name": "New Component To Add"} {{#if(not(varCurrentComponents.isEmpty))}}, {{/}} {{varCurrentComponents}}
Like John Funk likes this
1 vote
Martin Kaethner
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 8, 2023

I had the same problem: "copy from issue" wasn't available.

Luckly the Jira knowledge base helped out: https://confluence.atlassian.com/automationkb/how-to-add-components-to-issues-with-automation-rules-in-jira-1021222395.html

 

append one component

{
    "update": {
        "components": [{
            "add": {"name": "Name of the Component"}
        }]
    }
}

 

append multiple components

{
    "update": {
        "components": [{
            "add": {"name": "Name of the Component"}
        }, 
        {
            "add": {"name": "Name of another Component and so on"}
        }]
    }
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events