Confluence has been updated to version 6.15.9


Recently we had a request to synchronize data from the text custom field on one side into the select list on the other side. 

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

final def textFieldCfName = "Text Custom Field Name"

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

Receiving side

Incoming sync

final def nygSelectListCfName = "Select List Custom Field Name" 

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