I would like to use scriptrunner to return the value of a custom field of a linked issue. Can someone provide me a script that can do this?

c bolton November 9, 2015

I would like to use scriptrunner to return the value of a custom field of a linked issue. Can someone provide me a script or sample that can do this?

1 answer

1 vote
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 9, 2015

Hi 

The script below can give you an idea of how to get the first linked issue's custom field value. 

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def loggedUser = ComponentAccessor.getJiraAuthenticationContext().getUser().directoryUser
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def issue = issueManager.getIssueObject("issue-key")
// Get all the linked issues
def allLinkedIssues = issueLinkManager.getLinkCollection(issue, loggedUser).allIssues
 
//Check if list is empty or null
if (!allLinkedIssues)
	return 
def firstIssue = allLinkedIssues[0]
//Get the custom field with the specific name
def tgtField = customFieldManager.getCustomFieldObjects(firstIssue).find {it.name == "customField-name"}

return firstIssue?.getCustomFieldValue(tgtField)

 

You can also have a look, what the issueLinkManager can give you (depending on your case). 

Regards

Thanos

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events