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

Automation | find and set value for a dropdown customfield

Andrei Margarint
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!
June 7, 2023

I have a customfield_11312 (single select dropdown) with values like clientName-clientId ex. google-112233.
In automation I have a variable (smart) that extracts the clientId from issue description.
Question: How can I find (extract/find id) and set the value for customfield_11312, having only the clientId? Didn't find a solution to search/iterate on the values of a customfield dropdown to find the correct value.

2 answers

5 votes
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 8, 2023

Hi @Andrei Margarint - just wanted to clarify, the options for customfield_11312 are things like:

  • google-112233
  • yahoo-223344
  • apple-334455
  • roku-445566

And your Description field includes something like:

Id: 223344

And you want to match that against:

  • yahoo-223344

If you happen to be on Jira Cloud, well are a few options (heh).

Lookup Table

If you do not have a lot of options, you could manually create a Lookup Table like this:
Screenshot 2023-06-07 at 11.41.50 PM.png

And then you could Edit the issue and set your custom field value to the smart value:

 {{matchId.get(companyId)}}

Where {{companyId}} is the id you've parsed out of Description.

(My custom field is named "Single Select List".)

Screenshot 2023-06-08 at 12.17.23 AM.png

Get list of options via API and iterate through them

However I hate doing this manually. The REST API lets us get the list of options for a custom field, so I wondered if I could leverage my favorite hack, accessing the Jira API through the Web request action. (That link has the details on how to get a Personal Access Token that you'll need for the Authorization header.)

You'll need to do a little bit of digging with the API to figure out the correct URL. You should be able to open a link like this (substitute in your sitename) in a browser window (ideally with Firefox which presents JSON nicely, or with this Chrome JSON viewer extension):

https://YOURSITE.atlassian.net/rest/api/3/field/customfield_11312/context

This should return a JSON blob that includes the context id for your options, which you would then add to the URL:

https://YOURSITE.atlassian.net/rest/api/3/field/customfield_11312/context/YOURCONTEXTID/option

Once you have that, you can plug it into the Web request action, using the GET method. Be sure to check "Delay execution of subsequent rule actions until we've received a response for this web request":Screenshot 2023-06-08 at 12.03.51 AM.png

For my testing I used a Manual trigger and manually input the company id. You're parsing it out from Description, so in later examples you'll see {{companyId} again.

Advanced Branching

From there it's a matter of using Advanced branching to iterate over each of the options returned in the API call, in the smart value {{webhookResponse.body.values}}, which we are referencing as option:

Screenshot 2023-06-08 at 12.22.45 AM.png

For each option, we do a comparison of the Id (which we extract with some text functions) against the {{companyId}}.

Here's how we extract just the id from the option value:

{{option.value.right(option.value.length.minus(option.value.indexOf("-").plus(1)))}}

Set the field value

If we get a match, we set the field value:

Screenshot 2023-06-08 at 12.27.14 AM.png

And... that's it!

I hope that you're on Cloud so you can get to try this. It's pretty cool.

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 26, 2023

Hi @Andrei Margarint - I was wondering if you had a chance to give this a try, or had any questions.

0 votes
Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 7, 2023

Hi @Andrei Margarint 

 

As I know automation don't have feature like that. Only option as I see will be use conditions ex. if value is 112233 set google-112233 as a value.

 

Regards,

Seba

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events