Extracting more complex data from an issue retrieved via a webHook (Jira Automation)

Guy Slade July 13, 2024

This is well beyond my limited knowledge of Json and how to manipulate things. I have an Epic that has been updated with a new Parent Link (initiative). This triggers my automation. For whatever reason, although I have the id of the Parent Link issue I do not get any of it's data and so I have had to retrieve the Parent Link issue via a restful call in a web hook action.
I want to set the components of the Epic to be the same as its parent Initiative. I am at a loss as to how to do this. I don't even know if it is possible for me to do this. I understand what the error message is telling me.... it wants an array of something. But should be an array of names, or ids? And is it possible to build an array of the right things from the info I have in the format it is in?
I have a write to log of: 

Components are: {{webhookResponse.body.fields.components}}

and an advanced update issue action of:

{ "fields": { "components": "{{webhookResponse.body.fields.components}}" } }

Below is what this gives me
Screenshot 2024-07-13 at 5.17.19 PM.png

1 answer

1 accepted

1 vote
Answer accepted
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.
July 13, 2024

Hi @Guy Slade 

When setting the components with JSON in a rule, please try the array syntax:

https://support.atlassian.com/cloud-automation/docs/advanced-field-editing-using-json/#Components

As you are getting the data from the webhookResponse, first check if that is a list or an array by writing the value to the audit log.  That will help to know how to convert it before use in the JSON.

If that does not help, please post an image of your complete rule and of the Edit Issue action details to provide more context.

Kind regards,
Bill

Guy Slade July 14, 2024

Hi Bill, I have written out what the response gives for body.fields.components above. I also have the content of the edit issue action up there. I am not sure what to make of the components I get back. Is it a list of lists?

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.
July 15, 2024

Yes, it is a list element, as text, and so the names of the components is this:

{{webhookResponse.body.fields.components.name}}

Using the components element directly in the edit likely does not work because the type is not recognized.  You may make the dynamic JSON for the edit by iterating over the values:

{
"fields: {
"components" : [
{{#webhookResponse.body.fields.components.name}}
{ "name" : "{{.}}" }{{^last}}, {{/}}
{{/}}
]
}
}

That will add each component by name, with a comma separated the entries.

Guy Slade July 16, 2024

Thanks Bill, that worked. My homework is now to dissect your solution and understand what it is doing :).... I have lots to learn..... I have never seen '#' before, I also don't know how to read:

"{{.}}" }{{^last}}, {{/}}
{{/}}

Anyway, thank you 

Suggest an answer

Log in or Sign up to answer