Forums

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

Copy linked issue value to Issue picker field

Poojaa Sudhakaran
Contributor
March 30, 2020

Hi there,

I have a use case where I need to copy linked issue value to a custom field named "Initiative Link" on issue creation. I have added a Post function in the very first transition, the one between the start and first status.

With the below code, Inward and Outward links are displayed as empty arrays even though the field values are passed and because of this, the rest of the code is not being executed. Would be great if you could point out what is failing here.

Thanks a ton!

Poojaa

 

import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.link.IssueLinkManager

def linkType = ["Is parent of"]
IssueLinkManager linkMgr = ComponentAccessor.getIssueLinkManager()

CustomField initiativeLink = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('Initiative Link');

log.warn "issue Summary: ${issue.getSummary()}"
log.warn "Inward links: ${linkMgr.getInwardLinks(issue.id)}"
log.warn "Outward links: ${linkMgr.getOutwardLinks(issue.id)}"

for (IssueLink link in linkMgr.getOutwardLinks(issue.id)) {
log.warn "Inside for: ${link.issueLinkType.inward}"
log.warn "${linkType.contains(link.issueLinkType.inward)}"
if (linkType.contains(link.issueLinkType.inward)) {
log.warn "inside if: ${link.destinationObject}"
issue.setCustomFieldValue(initiativeLink,link.destinationObject)
break
}
}
ComponentAccessor.getIssueManager().updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),issue,EventDispatchOption.ISSUE_UPDATED, false)

 

0 answers

Suggest an answer

Log in or Sign up to answer