Could you help me to sync component system field with custom field? sample script would be helpful.
Comments:
Javier Pozuelo commented on 28 September 2023
Hello Praveesh,
Which system field are you trying to sync, and what custom field type would you be using? Also, could you mention which issue trackers are you using?
Regards,
Javier Pozuelo
Praveesh commented on 29 September 2023
Hello Javier Pozuelo,
thanks for the reply.
I’m trying to sync the default “Components” system field in Atlassian Jira cloud (Source) to custom filed type “Select List (multiple choice)” in another Jira cloud (Destination). We can change destination custom field type as it’s just to hold data coming from source, means one way sync only.
Make sure you create components in your Jira cloud (Source) with the same names as the custom field select list values in your Jira Cloud (Destination).
Place the following in your Outgoing Sync in Jira Cloud (Source)
replica.components = issue.components
Incoming Sync in Jira Cloud (Destination)
def currentComponentNames = (issue.customFields."Components".value ?: []).collect { it.value }
def newComponentNames = replica.components.findAll { component -> component.name }
// Add new components to customField if they don't already exist
currentComponentNames.addAll(newComponentNames.findAll { it -> !currentComponentNames.contains(it) })
// Remove components from customField if they are not in replica.components
currentComponentNames.removeAll { it -> !newComponentNames.contains(it) }
// Clear customField if replica.components is empty
if (replica.components.isEmpty()) {
issue.customFields."Components".value = null
} else {
issue.customFields."Components".value = currentComponentNames
}