Originally asked by Daniel Carvajal on 14 July 2022 (original question)
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.
Originally asked by Daniel Carvajal on 14 July 2022 (original question)
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.
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:
replica.customFields."SimpleTestField" = issue.customFields."SimpleTestField"
Jira On-Prem Incoming
// 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()
}
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.