Forums

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

Need Help with Jira Automation for Multi-Select Field

Björn Trier August 9, 2023

 Good Day together,

I'm facing a bit of a challenge with Jira Automation and I'm hoping someone can guide me in the right direction. Here's my desired result in a Jira Automation Set Block:

 

 {
"fields": {
"customfield_12029": [{"value": "Freiburg"}, {"value": "Wiesbaden"}]
}
}

However, the issue I'm encountering is that I only have the values "Freiburg" and "Wiesbaden" within the issue description as "Freiburg,Wiesbaden". I'm unsure about how to achieve the desired outcome using automation. 

The complexity arises from the fact that the number of locations is dynamic, and it seems like I might need some sort of "for loop" to create the objects for the array.

While handling a single value is manageable, dealing with two values in a single string has proven to be quite challenging.

Splitting the string seems like an option, but due to the variable count of values, I can't implement this approach effectively. Additionally, setting 10 values, to cover ten possible values of which n could be null values, is not feasible because the function fails when attempting to set null values in a multi-select field.

I'd greatly appreciate any insights or ideas on how I could approach this problem and achieve the desired outcome using Jira Automation. Thanks in advance for your assistance!

I could use scriptrunner but my attempts to do so where not successful so far. 

Best regards,

Björn Trier

3 answers

1 accepted

2 votes
Answer accepted
Björn Trier August 9, 2023

So i found conditional smartValues, and this is kind of bad looking but operational for me :

Its just checking if the Value exists and if it does it inserts the object with the value in to the array, for a set amount of possible selections. 

{

    "fields": {

        "customfield_14010": [

            {{#if(exists(issue.description.match("Zugang:(.*)").split(",").get(0)))}}

            {

                "value": "{{issue.description.match("Zugang:(.*)").split(",").get(0)}}"

            }

            {{/}}

            {{#if(exists(issue.description.match("Zugang:(.*)").split(",").get(1)))}}

            ,{

                "value": "{{issue.description.match("Zugang:(.*)").split(",").get(1)}}"

            }

            {{/}}

            {{#if(exists(issue.description.match("Zugang:(.*)").split(",").get(2)))}}

            ,{

                "value": "{{issue.description.match("Zugang:(.*)").split(",").get(2)}}"

            }

            {{/}}

            {{#if(exists(issue.description.match("Zugang:(.*)").split(",").get(3)))}}

            ,{

                "value": "{{issue.description.match("Zugang:(.*)").split(",").get(3)}}"

            }

            {{/}}

            {{#if(exists(issue.description.match("Zugang:(.*)").split(",").get(4)))}}

            ,{

                "value": "{{issue.description.match("Zugang:(.*)").split(",").get(4)}}"

            }

            {{/}}

            {{#if(exists(issue.description.match("Zugang:(.*)").split(",").get(5)))}}

            ,{

                "value": "{{issue.description.match("Zugang:(.*)").split(",").get(5)}}"

            }

            {{/}}

            {{#if(exists(issue.description.match("Zugang:(.*)").split(",").get(6)))}}

            ,{

                "value": "{{issue.description.match("Zugang:(.*)").split(",").get(6)}}"

            }

            {{/}}

        ]

    }

}
Markus W_ BENES
Contributor
August 9, 2023

@Björn Trier Thanks for posting your solution; can be usefull also in other contexts :)

0 votes
Guilherme Pereira
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 3, 2025

Hello!

Found this post while trying to solve a similar issue. I needed to update a multiselect field with the results of a query I have on Metabase.

This was how I handled it.

jira ss.jpg

PUT request body:

{

    "fields": {

        "customfield_10151": [

            {{#webResponse.body.data.rows.get(0).get(1)}}{

                "value""{{.}}"

            }{{^last}},

            {{/}}{{/}}

        ]

    }

}

Explanation:

{{#webResponse.body.data.rows.get(0).get(1)}} -> iterates my result list with all the values I want to replace on the custom field

{"value": "{{.}}"} -> the string outside of smartvalues syntax is used to make sure my json will be formatted as required by JIRA's API. {{.}} is used to get the current element value (that is being iterated by the smartvalues expression
explained above).

{{^last}}, -> this makes sure that all items, except the last item iterated in my array, will be followed up by a comma character.

{{/}}{{/}} -> denotes the end of my iteration on the result set.

0 votes
Markus W_ BENES
Contributor
August 9, 2023

@Björn Trier is the field you want to write your values of the type Multi-Select Field?

Björn Trier August 9, 2023

Yes but i found a solution. A kind of ugly one, but one.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events