Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to add new components to an issue using advanced json

Hello,

 

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

0 votes
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,

Bill

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.

__Bill

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!

__Bill

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:

https://codebarrel.atlassian.net/issues/?jql=project%20%3D%20AUT%20AND%20resolution%20%3D%20Unresolved%20AND%20description%20%20~%20%22epic%20link%22%20AND%20(description%20~%20%22trigger%22%20OR%20description%20~%20%22change%22)%20ORDER%20BY%20Key%20DESC

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.

__Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,047 views 8 28
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you