Confluence has been updated to version 6.15.9

Exalate allows syncing any kind of custom field type combination.

This article shows how to synchronize data between a select list and a text custom fields.


Select-list to Text Custom Field

For example, you have a custom field called Sports List (select list Single Choice) and you want to sync it to the custom field Sport Type (text field). 

Sending side

Outgoing sync

Send the select-list value to the remote side 

replica.customFields."Sports List"  = issue.customFields."Sports List"

Receiving side  

Incoming sync

replica.customFields."Sports List".value is an object of type option.  The option contains a value, which is the string of the option. 

issue.customFields."Sport Type".value is a text type custom field, which includes string value 

issue.customFields."Sport Type".value = replica.customFields."Sports List".value.value

Text Custom Field to Select-list

The scripts below help to send the text custom field value to the destination side and add a new option to the existing select list field if there is no such option yet.

Sending side

Outgoing sync


// SETTINGS
final def textFieldCfName = "Text Custom Field Name"
// END SETTINGS

def localOptionValue = issue.customFields[textFieldCfName]?.value
if (localOptionValue == null) {
    throw new com.exalate.api.exception.IssueTrackerException(
    "Can not synchronize 
            `"+textFieldCfName+"` 
                to destination jira since there is no value set for issue 
           `"+ issueKey.URN +"` 
            ("+issueKey.id+"
    )"
  )
}
replica.customKeys."Text field Value" = localOptionValue

Receiving side  

Incoming sync

// SETTINGS
final def nygSelectListCfName = "Select List Custom Field Name" 
// END SETTINGS


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.context.IssueContext

def cfm = ComponentAccessor.getCustomFieldManager()
def om = ComponentAccessor.getOptionsManager()

def remoteOptionValue = replica.customKeys."Text field Value" as String
def cf = cfm.getCustomFieldObjectsByName(nygSelectListCfName).find()
def fCfg = cf.getRelevantConfig(IssueContext.GLOBAL)
def localOptions = om.getOptions(fCfg)
if (!localOptions.any { o -> o.value == remoteOptionValue }) {
    //FieldConfig fieldConfig, Long parentOptionId, Long sequence, String value
    om.createOption(fCfg, null, 0L, remoteOptionValue)
}

In case an issue is not synchronized and you wand to trigger synchronization by updating the issue filed, you need to create a JQL trigger.

See Also