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

April_Delay
Contributor
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

2 votes
Answer accepted
April_Delay
Contributor
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

Like Rafa likes this
Karen Corbeill
Contributor
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.

Like # people like this
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
Contributor
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 # people like this
4 votes
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"}
        }]
    }
}
Almuth Boehme _Communardo_
Contributor
November 28, 2024

This solved it for me, thanks! I was trying to set one or more components according to one or more asset objects ("App") that were set on the request.

To make sure I'm not appending components to an incorrect initial set, I first clear the component field and then iterate over the asset objects.

automation.png

JSON for the advanced edit issue fields action:

{
"update": {
"components": [{
"add": {"name": "{{ProductApp.Component}}"}
}]
}
}

 

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.
November 28, 2024

Hi @Almuth Boehme _Communardo_ 

First thing: for the piece of the rule you show, there is an Edit on the Components field and then they are apparently updated again later, but without first using the Re-fetch Issue action.  As a result, the later edits may not work as expected.

 

Next, using an advanced branch over the values may lead to errors and collisions in the edits.  The reason is branches which could be on more than one thing are executed in parallel and asynchronously, with no guarantee of processing order or when the branch will complete...up until the last step of the rule.  This means each attempted edit with the JSON could collide, and potentially fail.

This is why the other posts in this thread suggest using one single edit which iterates over the values, creating a single JSON expression.

 

Kind regards,
Bill

Almuth Boehme _Communardo_
Contributor
November 28, 2024

@Bill SheboyI'll have a look at it in case I run into issues, so far my tests were successful.

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.
November 28, 2024

I am certain that rule may have problems with collisions in the future, and strongly suggest changing it.  The log may not show errors; instead some component values will either not save or will be "walked over" during later saves.

To learn more about such branch behavior, please see this note in the documentation: https://support.atlassian.com/cloud-automation/docs/jira-automation-branches/#Ordering-of-branch-executions

Almuth Boehme _Communardo_
Contributor
December 3, 2024

I tested checking the field values on the issues, not the audit log. Up to 16 components were no problem. When components are updated each new component added is a single action according to the history on the request, even if you do it manually and it looks like you made only one save action to the components field. Therefore I think branching isn't much of an issue as long as it's an append action.

Suggest an answer

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

Atlassian Community Events