Confluence has been updated to version 6.15.9

JIRA SERVERJIRA CLOUD

This article describes how to synchronize custom fields that have options as a value type. 

Jira has different custom field types with options:

  • Select list (Single choice)
  • Radio buttons (list of radio buttons)
  • Select list (Multiple choices)
  • Checkboxes (multiple choices)

Exalate helper method getOption handles custom fields that use the value type as Option.

Below you can find some examples of handling the most common cases for the custom field with option values.

Select list (single choice)

Custom fields with types Select List(single choice) and Radio buttons(single choice) have values of type Option

  • set the option Running into the local custom field Hobby

    issue.customFields."Hobby".value = nodeHelper.getOption (issue, "Hobby", "Running")
    // For Jira Server works starting from Exalate 4.4.5
    issue.customFields."Hobby".value = "Running"

  • add the value from the remote custom field Interest  into the local custom field Hobby

    If the received custom field does not have any values yet, you can still set a custom field with an empty value on your side as on the example below.

    // For Jira Server works starting from Exalate 4.4.5
    issue.customFields."Hobby".value = replica.customFields."Interest"?.value?.value
    issue.customFields."Hobby".value = nodeHelper.getOption(issue, "Hobby", replica.customFields."Interest"?.value?.value)

Select list (multiple choices)

Custom fields with types Select List(multiple choices) and Checkboxes(multiple choices) have values of type list of Options.

Below you can find some examples of how to handle custom field options in multi-value custom fields. 

  • add the value from the remote custom field Departments  into the local custom field Sub-divisions

// For Jira Server works starting from Exalate 4.4.5
issue.customFields."Sub-divisions".value = replica.customFields."Departments"?.value?.collect { opt -> opt?.value }


issue.customFields."Sub-divisions".value = nodeHelper.getOptions(
  issue,
  "Sub-divisions",
  replica.customFields."Departments"?.value?.collect { opt -> opt?.value }
)


How to set default option values in a custom field?

You can set a default value as a custom field option. In case option values in your instance are different from the ones received from the remote side.

Check some examples below:

Select list (single choice)

Assign an option to the field for the custom field Customer Address which is a select list (single choice) assign an option to the field using a nodeHelper.getOption method

// For Jira Server works starting from Exalate 4.4.5
issue.customFields."Customer Address".value = 
	replica.customFields."Address"?.value?.value ?:
	"1600 Amphitheatre Parkway Mountain View, CA 94043"

Set the received value from the remote custom field Interest to the local custom field Hobby

issue.customFields."Hobby".value = nodeHelper.getOption(
	issue, 
	"Hobby", 
	replica.customFields."Interest"?.value?.value
) ?: nodeHelper.getOption(issue, "Hobby",  "Running")

Select list (multiple choices)

For custom fields of type select list(multiple choices), you need to ensure that the value is an array of options

The default value should be inside the brackets:  [ nodeHelper.getOption( issue,"Hobby","Running" ) ]

If the remote side didn't send the value from the custom field Interest, set a default value as Running to the local custom field Hobby

// For Jira Server works starting from Exalate 4.4.5
issue.customFields."Hobby".value = 
	replica.customFields."Interest"?.value?.collect { opt -> opt?.value } ?: 
	["Running"]
issue.customFields."Hobby".value = nodeHelper.getOptions(
  issue, 
  "Hobby", 
  replica.customFields."Interest"?.value?.collect { opt -> opt?.value }
) ?: [
  nodeHelper.getOption(
            issue,"Hobby","Running"
  )
]

Set a value to the local custom field manually

issue.customFields."Multi Select Custom Field name".value = 
                (issue.customFields."Multi Select Custom Field name".value ?: []) + 
                    nodeHelper.getOption(issue, "Multi Select Custom Field name", "MY STATIC OPTION")



Back to Custom fields synchronization