How to Sync Group Picker Custom Fields in Jira On-premise

    This article shows how to synchronize Group Picker Jira custom field.

    Jira provides an advanced custom field Group Picker (single group or multiple groups) which helps to choose a user group(single or multiple) in a popup picker window. You can synchronize the field values using Exalate. When syncing the group picker field Exalate checks whether the group with a certain name exists on the remote side. In case the group with such a name does not exist on the receiving side you can do the following:

    • set default value
    • create a group with the received group name and set the value to the custom field on the receiving side (applicable only for Jira Server)
    • don't set any value and skip the sync of this field

    Below you can find examples of the group picker filed(single or multiple groups) synchronization for the last option: when the group does not exist on the remote side - don't set any value.

    Jira Server

    Group Picker(single group) Synchronization

    Source side

    Outgoing sync

    if (issue.customFields."Group picker custom field name"?.value instanceof Iterable) {
        issue.customFields."Group picker custom field name".value = issue.customFields."Group picker custom field name".value.find()
    }
    replica.customFields."Group picker custom field name" = issue.customFields."Group picker custom field name"

    Destination side

    Incoming sync

    def remoteGroup = replica.customFields."Group picker custom field name"?.value?.name?.asString
    if (remoteGroup) {
        def gm = com.atlassian.jira.component.ComponentAccessor.groupManager
        def group = gm.getGroup(remoteGroup)
        if (group) {
            issue.customFields."Group picker custom field name".value = [group]
        }
    } else {
        issue.customFields."Group picker custom field name".value = null // don't sync the group picker field if a local group is not found
    }

    Group Picker (multiple groups) Synchronization

    Source side

    Outgoing sync

    if (issue.customFields."Group picker custom field name"?.value instanceof Iterable) {
        issue.customFields."Group picker custom field name".value = issue.customFields."Group picker custom field name".value.find()
    }
    replica.customFields."Group picker custom field name" = issue.customFields."Group picker custom field name"

    Destination side

    Incoming sync

    def remoteGroups = replica.customFields."Group picker custom field name"?.value?.collect { it.name?.asString }
    if (remoteGroups?.any { it != null }) {
        def gm = com.atlassian.jira.component.ComponentAccessor.groupManager
        def groups = remoteGroups
            .collect { g -> gm.getGroup(g) }
            .findAll()
        
        issue.customFields."Group picker custom field name".value = groups
    } else {
        issue.customFields."Group picker custom field name".value = []
    }