Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How to add new components to an issue using advanced json



I want to add a new component to an issue on an automation event and it says how below advanced json can be used to set components, but in case my case I know the id of the component and I want to add to list of components and not remove them. 


"components" : [ { "name": "Active Directory"} , { "name": "Network Switch" } ]

 I tried

"update" : {
"components" : [{"add" : [{"name" : "Rollout"}]}]

but it gives json error on runtime

1 answer

1 accepted

1 vote
Answer accepted

Hi @manas Sahoo  -- Welcome to the Atlassian Community!

The trick here is to gather the existing components first, and then append your new value.  Then use advanced edit with the JSON as you note.  Remember that the component must already exist for the project.

For an example rule:

  • Trigger: manual (or whatever you need)
  • Action: create variable with the JSON for your current components.  Let's call it firstJson.
{{#issue.components}}{ "name": "{{name}}"} {{^last}}, {{/}}{{/}}
  • Action: create a second variable, called secondJson, doing whatever you need to add your new component, adding it to the string.  In this example, I'll arbitrarily assume it is in the Description.  For your case, it appears to be hard-coded to "Rollout"
{{firstJson}} , { "name": "{{issue.description}}"}
  • Action: finally used advanced edit to replace the components
"fields": {
"components" : [ {{secondJson}} ]

You may combine the second and third steps (building the JSON) if you have a simple way to determine the component to add.


Best regards,


Thank you Bill, I tried to copy paste as you have said and I am still getting an error

that Error while parsing additional fields. Not valid JSON.


Is there a way to know which one is causing the issues out of the below 3 steps


{{#issue.components}}{ "name": "{{name}}"} {{^last}}, {{/}}{{/}}


{{firstJson}} , { "name": "{{ "Rollout_Portugal" }}"}


"fields": {
"components" : [ {{secondJson}} ]

Ok  I found the issue in 2nd statement and changed it to 

{{firstJson}} , { "name": "Rollout_Portugal" }


But it fails if the jira has blank components, it works if the jira had components already. What is the best way to make it work for both scenarios ?

I applied 2 branches and used a condition to use the above logic if components is already blank for the issue and that has worked well

Like Bill Sheboy likes this

Hi!  It is this one: 

{{firstJson}} , { "name": "{{ "Rollout_Portugal" }}"}

I gave as an example using a field from the issue.  When you are using a hard-coded value you can remove the extra brackets.  Please try this one:

{{firstJson}} , { "name": "Rollout_Portugal"}

My apologies that my example led you astray.


Well done diagnosing the issues!  The action Log to write to the audit log can help solve such problems also.  For example, write pieces of JSON or field values to the log as you work to see where there are problems.

If this approach helped solved your question, please mark it as solved.  That will help others in the community find answeres to similar ideas faster in the future.  Thanks!


Like manas Sahoo likes this

Now I have created a rule to assign the component to all child objects when an epic has a certain label. Now I also want to make sure when a story is assigned to an epic with a specific label, we add the component to that story. I could not find the epic link as an field on field change event.  Do you know any way of catching the event of when a story of task is assigned to an epic ?

Nope, and there are several defects/suggestions to add triggering on Epic Link changes:

Your options may be to run a scheduled trigger rule, or to change an additional field that can be caught by the issue changed trigger.

Thank you Bill. Is it possible to create a rule which says


On Issue create ,

Check the linked Epic's components and if it contains component "Rollout" 

Then on this new issue, add component Rollout

Yes, I believe that is possible.

  • Trigger: issue created
  • Condition: trigger issue's component does not contain "Rollout" already
  • Branch: on the parent epic
    • Condition: epic's component contains "Rollout"
    • Actions... use the techniques we already noted to add "Rollout" to the trigger issue

Please try it and see what you get.

Also, you may want to consider creating a test project for experimenting on rules.  Then you can do what you wish and not worry about bending/breaking any existing project's issues.  When you have a rule working, you can re-create it in the target project, or ask your site-admin to copy it for you.


Hi @manas Sahoo and @Bill Sheboy  and thanks for advices!


I'm trying the same as in this case but I got stuck in this:
"But it fails if the jira has blank components, it works if the jira had components already. What is the best way to make it work for both scenarios ?

I applied 2 branches and used a condition to use the above logic if components is already blank for the issue and that has worked well"

This is working for me too when there is already some component in the issue, but not when there isn't any components. Error is the same: 

Error while parsing additional fields. Not valid JSON.

So, can you give me an example for this: "I applied 2 branches and used a condition to use the above logic if components is already blank for the issue and that has worked well" 

I do have 2 branches and 2 more variables which are made almost like the 2 first variables but with different names and reference to name thirdJson:

{{#issue.components}}{ "name": "{{name}}"} {{^last}}, {{/}}{{/}}

{{thirdJson}} , { "name": "{{ "Rollout_Portugal" }}"}

 what are the differences in those 2 branch rules? What I'm doing wrong?

Best regards,


Hi @Timo Vertanen 

For some context, would you please post an image of your complete rule?  That may help with suggestions on how to improve it.  Thanks!

Kind regards,

Hi @Bill Sheboy 

Hope these images helps:


third and fourth.pngthirdJson.png




Hi @Timo Vertanen 

First a suggestion: please consider using one of the free browser addons (or a screen-capture tool) to capture a scrolling browser window.  That will help to capture your entire rule in one image, making it easier to see what is happening.

Next, your use case is different from the original one in this post.  You are using branches on multiple issues, and as a result the processing occurs in parallel and asynchronously...often leading to unpredictable results for edits like you are trying.

Before we proceed, would you please explain the problem you are trying to solve.  Knowing that will help determine how/if the problem can be solved with an automation rule.


Hi @Bill Sheboy 

In my case there are project A and project B. Issue is created in project A and in some cases it creates a linked issue to project B.
When user adds (editing or resolving issue) in project B, the value "Ohjelmistovirhe" to a custom field "juurisyy" (Select List (Multiple choices)), then it should automatically add component "Bugi" to linked issue in project A.

I assumed that this automation rule would work for me, but only works when there is already some else component in the issue in project A.

Thanks for that information.  For your use case, there are a couple of approaches:

  • Conditionally process the components: use an if/else condition in order to handle the cases of "none" or "some" initial component values.  The different paths will lead to different actions for the additions later.
  • Add a "placeholder" component: early in the rule, always add a placeholder component of a known value.  Continue to process as you existing rule does.  At the end of the rule, remove the placeholder value.  Please note, this approach will not work if you are adding components within a branch.
Like Timo Vertanen likes this

@Bill Sheboy thank you for your help!

If my existing rule is not enough I'll try this "placeholder" solution.



Suggest an answer

Log in or Sign up to answer

Atlassian Community Events