Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira Automation: Custom Data with Smart Values

Yusuf Kör July 11, 2023

Hello, 
I created a web automation in Jira where I want it to send me a json with the fixVersions list. It should only contain the id and the released flag. I came up with the following solution. Is there a better solution where I don't have to loop and deal with json formatting?

```
{
"issue_id": "{{issue.id}}",
"issue_key": "{{issue.key}}",
"fixVersions": [
   {{#issue.fixVersions}}
   {
      "id": {{id}},
      "released": {{released}}
   }{{^last}},{{/}}
   {{/}}
   ]
}

```

 

or by filtering only the not-released ones

```
{
"issue_id": "{{issue.id}}",
"issue_key": "{{issue.key}}",
"fixVersions": [
   {{#issue.fixVersions}}
   {{#if(not(released))}}
   {
      "id": {{id}}
   }{{^last}},{{/}}
   {{/}}
   {{/}}
   ]
}
```

Thanks
Yusuf

1 answer

1 vote
Gideon Nolte _Eficode_
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 11, 2023

Hi @Yusuf Kör ,

this looks about right to me.

I would hide away some of the complexity in a variable. Let's say you create {{releasedVersionIds}} - which you set equal to:

[ {{#issue.fixVersions}} {{#IF(not(released))}}{{id}}{{^last}}, {{/}}{{/}}{{/}} ]

 This way you can easily set up your request data like this:

{
"issue_id": "{{issue.id}}",
"issue_key": "{{issue.key}}",
"fixVersions": {{releasedVersionIds}}
}

More concise and easier to read/understand.

Alternatively and depending on the runtime receiving the data you could just send the info in separate arrays like {{issue.fixVersions.id.asJsonArray}} and {{issue.fixVersions.released.asJsonArray}} and zip them in you receiving runtime. That would look like;

{
"issue_id": "{{issue.id}}",
"issue_key": "{{issue.key}}",
"fixVersionIds": {{issue.fixVersions.id.asJsonArray}},
"fixVersionReleaseState": {{issue.fixVersions.released.asJsonArray}}
}

Hope this helped. What's your thought on this?
Greetings
Gideon

Yusuf Kör July 11, 2023

Yes, that helped a lot. Many thanks

Suggest an answer

Log in or Sign up to answer