How to retrieve a custom field values from several linked issues and present it as list in one scripted field?

Hi

I'm trying to activate a scripted field that will retrieve a custom field value from several linked issues (different link types - Parent of, Child of etc..) and present the scripted field values as a list of values (as a string/list).

Trying the following code which gives me only one of the wanted values (the value from the last linked issue):

 

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue

def Issue issue = issue

def user = ComponentAccessor.getUserManager().getUserByName("admin").getDirectoryUser()
def issueLinkManager = ComponentAccessor.issueLinkManager

def linkCollection = issueLinkManager.getLinkCollection(issue, user)

if (linkCollection && linkCollection.allIssues) {
def CustomFieldManager customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObject("customfield_xxxxx")
def linkedIssue = linkCollection.allIssues.first()
return linkedIssue.getCustomFieldValue(customField)
}

2 answers

1 accepted

  1. You miss a brasket into the very end of an issue.
  2. Try using methods to get value. E.g. linkCollection.getAllIssues(), but not allIssues

To speed up development see this:https://answers.atlassian.com/questions/32982259

I modify it a little to get value from first linked issue into list.

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue


def Issue issue = issue;
def user = ComponentAccessor.getUserManager().getUserByName("vzverev").getDirectoryUser()
def issueLinkManager = ComponentAccessor.issueLinkManager
def linkCollection = issueLinkManager.getLinkCollection(issue, user)
if (linkCollection && linkCollection.getAllIssues()) {    
        def CustomFieldManager customFieldManager = ComponentAccessor.customFieldManager
        def customField = customFieldManager.getCustomFieldObject("customfield_xxxx")        
    	for(Issue curLinkedissue: linkCollection.getAllIssues()){       	 
           	return curLinkedissue.getCustomFieldValue(customField)
    }
}

Thank you Vasily,

Your help was very useful and I eventually used the aforementioned code with a little addition and it works well:

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue


def Issue issue = issue;
def user = ComponentAccessor.getUserManager().getUserByName("xxxxx").getDirectoryUser()
def issueLinkManager = ComponentAccessor.issueLinkManager
def linkCollection = issueLinkManager.getLinkCollection(issue, user)
if (linkCollection && linkCollection.getAllIssues()) {
def CustomFieldManager customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObject("customfield_xxxxx")
def references = []
def curValue
for(Issue curLinkedissue: linkCollection.getAllIssues()){
curValue = curLinkedissue.getCustomFieldValue(customField)
if (curValue != null) {
references << curValue
}
}
String poReferences = references.join(",\r\n")
return poReferences
}

Suggest an answer

Log in or Join to answer
Community showcase
Emilee Spencer
Published Friday in Marketplace Apps

Marketplace Spotlight: DeepAffects

Hello Atlassian Community! My name is Emilee, and I’m a Product Marketing Manager for the Marketplace team. Starting with this post, I'm kicking off a monthly series of Spotlights to highlight Ma...

66 views 0 3
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot