It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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?

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

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published Apr 03, 2019 in Marketplace Apps

How to estimate projects more accurately?

Gaining insight into your team’s effectiveness and choosing the right estimation technique.   Estimating projects is hard. It is because people have the tendency to underestimate the time thin...

315 views 2 10
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you