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.

    CommentAdd your comment...

    1 answer


      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"
      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()
        CommentAdd your comment...