Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

how do I compare a dropdown to a text field?

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()def optionsManager = ComponentAccessor.getOptionsManager()def faveFruitOtherFld = customFieldManager.getCustomFieldObjectByName("Add New Vendor Name")def issueService = ComponentAccessor.getIssueService()def faveFruitFld = customFieldManager.getCustomFieldObjectByName("Vendor Name")

  def issue = event.issuedef otherFaveFruit = issue.getCustomFieldValue(faveFruitOtherFld) as String

import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.comments.CommentManagerimport com.atlassian.jira.user.ApplicationUserimport com.onresolve.jira.groovy.user.FieldBehaviours

import com.atlassian.jira.component.ComponentAccessor

final String groupName = "Procurement"

int numOfVendors = faveFruitFld.size()

for( int i = 0; i < numOfVendors ; i++ )
{        if (faveFruitFld[i] == faveFruitFld){            }    else    {              if (issue.reporter ? ComponentAccessor.groupManager.isUserInGroup(issue.reporter, groupName): true) {    
if (otherFaveFruit)             {    
    def fieldConfig = faveFruitFld.getRelevantConfig(issue)    def currentOptions = optionsManager.getOptions(fieldConfig)    def newSeqId = currentOptions*.sequence.max() - 1    def option = optionsManager.createOption(fieldConfig, null, newSeqId, otherFaveFruit)
    def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()    def issueInputParameters = issueService.newIssueInputParameters()    issueInputParameters.with {        addCustomFieldValue(faveFruitFld.idAsLong, option.optionId.toString())        addCustomFieldValue(faveFruitOtherFld.idAsLong, null)                    }    def updateValidationResult = issueService.validateUpdate(currentUser,, issueInputParameters)    if (updateValidationResult.isValid()) {        issueService.update(currentUser, updateValidationResult)    } else {        log.warn("Failed to update issue: ${issue.key}: ${updateValidationResult.errorCollection}")    } }

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def wertreporter =
def create = wertreporter + " added " + otherFaveFruit +" to the vendor dropdown "
CommentManager commentMgr = ComponentAccessor.getCommentManager()
//Der wirkliche KommentarcommentMgr.create(issue, currentUser, create, true)        }            }}

the above code is my attempt. 


I started with


how do I "check that the user-provided other value doesn’t actually already exist in the list"?


2 answers

Hi @Jacob francois here you go, explained:

First you have to put this code in the Behaviours "Dropdown" Field:

Select your text field in the selector and don't forget to change the "Other" option with your field "Other" option (maybe in ahother language) in the code.

import com.atlassian.jira.issue.fields.Field
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.onresolve.scriptrunner.parameters.annotation.FieldPicker
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

@FieldPicker(label = "Text field", description = "Your text field")
Field textField

FormField ffDropdown = getFieldById(getFieldChanged())
FormField ffTextField = getFieldById(textField.getId())

String selectedOption = ffDropdown.getValue() as String
Boolean isOtherSelected = selectedOption == "Other"


Second, you have to add the following code in a new Script Listener. Don't forget to select the project, the "Issue Updated" Event, the Dropdown field and the Text Field that you are using.

The code is commented to better understanding of what is doing:

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.changehistory.ChangeHistoryItem
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.Field
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.scriptrunner.parameters.annotation.FieldPicker

@FieldPicker(label = "Dropdown field", description = "Your dropdown field")
Field dropdownField
@FieldPicker(label = "Text field", description = "Your text field")
Field textField

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField cfTextField = customFieldManager.getCustomFieldObject(textField.getId())

Issue issue = event.getIssue()

//Checks if the Text Field is changed in the current "Issue Updated" Event
if (cfTextField.getName() in getFieldsChanged()*.getField()) {

String textFieldValue = issue.getCustomFieldValue(cfTextField) as String

//Checks if the Text Field have Text (it may be blank)
if (textFieldValue) {

OptionsManager optionsManager = ComponentAccessor.getOptionsManager()
CustomField cfDropdown = customFieldManager.getCustomFieldObject(dropdownField.getId())
FieldConfig dropdownFieldConfig = cfDropdown.getRelevantConfig(issue)
Options dropdownCurrentOptions = optionsManager.getOptions(dropdownFieldConfig)
Boolean isTextFieldValueInDropdownOptions = textFieldValue.toLowerCase() in dropdownCurrentOptions*.getValue()*.toLowerCase()
Option option

//Checks if the Text field value is currently in the dropdown options
//If not, creates a new option with the value from the Text Field
//If it's already in the current options just set the dropdown field with that option
//In both cases removes the Text Field's value
if (!isTextFieldValueInDropdownOptions) {
long newSeqId = dropdownCurrentOptions*.getSequence().max() - 1
option = optionsManager.createOption(dropdownFieldConfig, null, newSeqId, textFieldValue)
} else {
option = dropdownCurrentOptions.find { it.getValue() == textFieldValue }

updateIssue(issue, cfDropdown, cfTextField, option)

List<ChangeHistoryItem> getFieldsChanged() {
return ComponentAccessor.getChangeHistoryManager().getAllChangeItems(event.getIssue())?.findAll {
it?.getChangeGroupId() == event.getChangeLog()?.id

void updateIssue(Issue issue, CustomField cfDropdown, CustomField cfTextField, Option option) {

IssueService issueService = ComponentAccessor.getIssueService()
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()

issueInputParameters.with {
addCustomFieldValue(cfDropdown.getIdAsLong(), option.getOptionId().toString())
addCustomFieldValue(cfTextField.getIdAsLong(), null)

IssueService.UpdateValidationResult updateValidationResult = issueService.validateUpdate(currentUser, issue.getId(), issueInputParameters)
if (updateValidationResult.isValid()) {
issueService.update(currentUser, updateValidationResult)
} else {
log.warn("Failed to update issue: ${issue.getKey()}: ${updateValidationResult.getErrorCollection()}")

 I hope this is what your looking for.

thank you. I am not sure why this script isn't working. I'm not getting any errors via the listener screen. 

Hello Jacob,


could you please post script in code block so new lines are not altered? This way, code is hardly readable a understandable. Plus, could you please specify what you problem is (what errors you get) and when is the expected result?


Thank you and have a nice day!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

99 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you