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
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:
{{#issue.components}}{ "name": "{{name}}"} {{^last}}, {{/}}{{/}}
{{firstJson}} , { "name": "{{issue.description}}"}
{
"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}} ]
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I believe that is possible.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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,
Timo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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,
Bill
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.
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.
Thanks,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for that information. For your use case, there are a couple of approaches:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy thank you for your help!
If my existing rule is not enough I'll try this "placeholder" solution.
Thanks,
Timo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy, @Timo Vertanen smart solution, I am just wondering why we cannot use add/remove, I haven't tested it, but according to Advanced field editing using JSON. In the section Supported Fields and Operations, it stays:
If you’re creating or editing issues, you can query a project’s createmeta or an issue’s editmeta information to view supported fields and operations.
if you put in your browser:
https://<YOURSITE>.atlassian.net/rest/api/latest/issue/<issueKey>/editmeta
I got add and remove add are available operations:
"components": {
"required": false,
"schema": {
"type": "array",
"items": "component",
"system": "components"
},
"name": "Components",
"key": "components",
"operations": [
"add",
"set",
"remove"
]
If it is possible, then the solution can be simplified.
Now I know the reason, add and remove only support single operation (i.e. one element to add or remove at a time), but not a list of elements, as per the following link: Could not find valid 'id' or 'name' in object when using the ADD operation for REST API. You need to use the set operations, which allow more than one element, but this will set the field wit the values, it doesn't add the components to the existing component values.
Regards,
David
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.