# Text field to create an option on remote dropdown field (single select)

**URL:** <https://community.exalate.com/t/text-field-to-create-an-option-on-remote-dropdown-field-single-select/5256>\
**Category:** General Questions\
**Tags:** onpremise-jira, cloud-jira, jira, jiraserver, migrated\_question\
**Created:** [November 4, 2024, 7:53am UTC](https://community.exalate.com/t/text-field-to-create-an-option-on-remote-dropdown-field-single-select/5256 "2024-11-04T07:53:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:53am UTC](https://community.exalate.com/t/text-field-to-create-an-option-on-remote-dropdown-field-single-select/5256/1 "2024-11-04T07:53:47Z")

</div>

_Originally asked by Daniel Carvajal on 14 July 2022 [(original question)](https://oldcommunity.exalate.com/questions/58492327)_

* * *

Having a text field I want it to sync to a single select field on the remote end, therefore if the option on the single select field doesn’t exist, to have it created.

* * *

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 4, 2024, 7:53am UTC](https://community.exalate.com/t/text-field-to-create-an-option-on-remote-dropdown-field-single-select/5256/2 "2024-11-04T07:53:48Z")

</div>

_Answer by Daniel Carvajal on 14 July 2022_

This configuration can be achieved the following way, it contains a method to check against the value on the remote end and ignore the casing in order to avoid duplicate label creation.

(the text field is “SimpleTestField” and the dropdown filed in the below example is “labelDrop”):

Jira Cloud Outgoing:

```auto
replica.customFields."SimpleTestField" = issue.customFields."SimpleTestField"

```

Jira On-Prem Incoming

```auto
// SETTINGS
final def nygSelectListCfName = "labelDrop"
// END SETTINGS
 
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.context.IssueContextImpl
 
def cfm = ComponentAccessor.getCustomFieldManager()
def om = ComponentAccessor.getOptionsManager()
 
def remoteOptionValue = replica.customFields."SimpleTestField"?.value as String
def cf = cfm.getCustomFieldObjectsByName(nygSelectListCfName).find()//Long projectId, String issueTypeId
def project = issue.project?: nodeHelper.getProject(issue.projectKey)
def type = issue.type?: nodeHelper.getIssueType(issue.typeName, project.key)
def ctx = new IssueContextImpl(project.id as long, type.id)
def fCfg = cf.getRelevantConfig(ctx)

if (fCfg == null) {
    debug.error("couldn't find relevant config for project ${issue.project.id} + ${issue.type.id} for custom field use ${cf.name}")
}
def localOptions = om.getOptions(fCfg)

def localOption = localOptions.find( {allowedOption -> remoteOptionValue.equalsIgnoreCase(allowedOption.getValue())} )

if (!localOption){
      if (!localOptions.any { o -> o.value == remoteOptionValue }) {    
//FieldConfig fieldConfig, Long parentOptionId, Long sequence, String value
    om.createOption(fCfg, null, 0L, remoteOptionValue)
    }
} else {
    issue.customFields."labelDrop".value = localOption.getValue()
}

```

* * *

---

<div class="post-metadata">

**Author:** ![xl8bot](https://dub1.discourse-cdn.com/flex018/user_avatar/community.exalate.com/xl8bot/32/324_2.png) [@xl8bot](https://community.exalate.com/u/xl8bot)\
**Post date:** [November 6, 2024, 7:54am UTC](https://community.exalate.com/t/text-field-to-create-an-option-on-remote-dropdown-field-single-select/5256/3 "2024-11-06T07:54:22Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
