This article shows how to synchronize data between a select list and a text custom field.
Exalate allows syncing any kind of custom field type combination.
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.
1 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. The issue.customFields."Sport Type".value is a text type custom field, which includes string value.
1 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
1 // SETTINGS
2 final def textFieldCfName = "Text Custom Field Name"
3 // END SETTINGS
4
5 def localOptionValue = issue.customFields[textFieldCfName]?.value
6 if (localOptionValue == null) {
7 throw new com.exalate.api.exception.IssueTrackerException(
8 "Can not synchronize
9 `"+textFieldCfName+"`
10 to destination jira since there is no value set for issue
11 `"+ issueKey.URN +"`
12 ("+issueKey.id+"
13 )"
14 )
15 }
16 replica.customKeys."Text field Value" = localOptionValueReceiving side
Incoming sync
1 // SETTINGS
2 final def nygSelectListCfName = "Select List Custom Field Name"
3 // END SETTINGS
4
5
6 import com.atlassian.jira.component.ComponentAccessor
7 import com.atlassian.jira.issue.context.IssueContext
8
9 def cfm = ComponentAccessor.getCustomFieldManager()
10 def om = ComponentAccessor.getOptionsManager()
11
12 def remoteOptionValue = replica.customKeys."Text field Value" as String
13 def cf = cfm.getCustomFieldObjectsByName(nygSelectListCfName).find()
14 def fCfg = cf.getRelevantConfig(IssueContext.GLOBAL)
15 def localOptions = om.getOptions(fCfg)
16 if (!localOptions.any { o -> o.value == remoteOptionValue }) {
17 //FieldConfig fieldConfig, Long parentOptionId, Long sequence, String value
18 om.createOption(fCfg, null, 0L, remoteOptionValue)
19 }In case an issue is not synchronized and you want to trigger synchronization by updating the issue filed, you need to create a JQL trigger.