Automation | find and set value for a dropdown customfield
Asked by Andrei Margarint:

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.


Answers:
author: Darryl Lee
body: Hi [@Andrei Margarint](/t5/user/viewprofilepage/user-id/5237636) - 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](https://community.atlassian.com/t5/Automation-articles/New-Automation-action-Create-lookup-table/ba-p/2311333) {#toc-hId--464224776}
---------------------------------------------------------------------------------------------------------------------------------------------------

If you do not have a lot of options, you could manually create a [Lookup Table](https://community.atlassian.com/t5/Automation-articles/New-Automation-action-Create-lookup-table/ba-p/2311333) like this:  
![Screenshot 2023-06-07 at 11.41.50 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/261956i1BA7597004F673F3/image-size/large?v=v2&px=999 "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](https://community.atlassian.com/t5/image/serverpage/image-id/261958iDEC47CF1B8C6A871/image-size/large?v=v2&px=999 "Screenshot 2023-06-08 at 12.17.23 AM.png")

Get list of options via API and iterate through them {#toc-hId-2023288057}
--------------------------------------------------------------------------

However I hate doing this manually. The [REST API](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-custom-field-options/#api-rest-api-3-field-fieldid-context-contextid-option-get) 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](https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Send-web-request-using-Jira-REST-API/ba-p/1443828). (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](https://chrome.google.com/webstore/detail/json-viewer/gbmdgpbipfallnflgajpaliibnhdgobh) 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](https://support.atlassian.com/cloud-automation/docs/actions-in-confluence-automation/#Send-web-request), 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](https://community.atlassian.com/t5/image/serverpage/image-id/261955iB58508EF692F1032/image-size/large?v=v2&px=999 "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 {#toc-hId-916898172}

From there it's a matter of using [Advanced branching](https://community.atlassian.com/t5/Automation-articles/Branching-over-smart-values-in-Jira-Automation/ba-p/1741935) 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](https://community.atlassian.com/t5/image/serverpage/image-id/261960iB324FC076B253E59/image-size/large?v=v2&px=999 "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](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/)) 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 {#toc-hId--890556291}

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

![Screenshot 2023-06-08 at 12.27.14 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/261961i6A9538DFDB58AD80/image-size/large?v=v2&px=999 "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.

comments: author: Darryl Lee
body: Hi [@Andrei Margarint](/t5/user/viewprofilepage/user-id/5237636) - I was wondering if you had a chance to give this a try, or had any questions.


author: Sebastian Krzewi?ski
body: Hi [@Andrei Margarint](/t5/user/viewprofilepage/user-id/5237636)

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