Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Copy custom field value from child issue(LinkedIssue) to parent issue

peter_zubkov March 8, 2020

Hi all,

 

I have this code that seems to make the opposite, its copy from Parent to Child.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants


final String fieldNameToCopy = "LastUpdate"


final String issueLinkTypeName = "Customer Portal issues"

def fieldManager = ComponentAccessor.fieldManager
def fieldToCopy = fieldManager.allAvailableNavigableFields.find { it.name == fieldNameToCopy }
def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id)

def linkedIssue = issueLinkTypeName ?
linkedIssues.findAll { it.issueLinkType.name == issueLinkTypeName }.last().destinationObject :
linkedIssues.last().destinationObject

def fieldToCopyId = fieldToCopy.id

switch (fieldToCopyId) {
case fieldManager.&isCustomFieldId:
def customField = ComponentAccessor.customFieldManager.getCustomFieldObject(fieldToCopyId)
def linkedIssueCustomFieldValue = linkedIssue.getCustomFieldValue(customField)
issue.setCustomFieldValue(customField, linkedIssueCustomFieldValue)
break

case IssueFieldConstants.COMPONENTS:
def commonComponents = linkedIssue.components.findAll { it.name in issue.components*.name }
issue.setComponent(commonComponents)
break

case IssueFieldConstants.FIX_FOR_VERSIONS:
def commonFixedVersions = linkedIssue.fixVersions.findAll { it.name in issue.fixVersions*.name }
issue.setFixVersions(commonFixedVersions)
break

case IssueFieldConstants.AFFECTED_VERSIONS:
def commonVersions = linkedIssue.affectedVersions.findAll { it.name in issue.affectedVersions*.name }
issue.setFixVersions(commonVersions)
break

default:
issue[fieldToCopyId] = linkedIssue[fieldToCopyId]
}

 

 

any advice on what needs to be changed?

thanks.

1 answer

0 votes
peter_zubkov March 12, 2020

.

Suggest an answer

Log in or Sign up to answer