Hi, I am jira dmin in our company and I am not really good at coding, so I have a "main" issue with key ESMOSD-xxxx and then I have a linked issues, which are some kind of "sub-tasks" but not sub-tasks exactly... And i need to check if the linked issue have key like "ESMOSV-xxxx" and if so, I need to copy the Assignee field of the linked issue into customfield named "Technik" in original servicedesk field "ESMOSD-xxxx"
I assembled some groovy code to be executed via workflow transiton, but it is just a hybrid from multiple web pages:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueFieldConstants
// the name of the field to copy
final String fieldNameToCopy = "Assignee"
// leave blank to copy from the last linked issue (regardless the link type)
final String issueLinkTypeName = "Vykazovanie"
def fieldManager = ComponentAccessor.fieldManager
def fieldToCopy = fieldManager.allAvailableNavigableFields.find { it.name == fieldNameToCopy }
if (!fieldToCopy) {
log.info "Could not find field with name $fieldNameToCopy"
return
}
def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id)
if (!linkedIssues) {
log.info "There are no linked issues"
return
}
if (issueLinkTypeName && !(issueLinkTypeName in linkedIssues*.issueLinkType*.name)) {
log.info "Could not find any issue, linked with the $issueLinkTypeName issue type"
return
}
def linkedIssue = issueLinkTypeName ?
linkedIssues.findAll { it.issueLinkType.name == issueLinkTypeName }.last().destinationObject :
linkedIssues.last().destinationObject
def fieldToCopyId = fieldToCopy.id
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def myCustomField = customFieldManager.getCustomFieldObject("customfield_13600")
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:
myCustomField = linkedIssue[fieldToCopyId]
}
I have managed to make it working If I am copying the assignee field of linked issue into assignee field of parent issue, but If I am trying to copy it into the customfield it fails without a single word in logs. The customfield which I am trying to copy into it is type "Single user picker" if this is a problem it can be changed to text type CF... PLS help