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)
}
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) } }
Hi Vasiliy,
I am pretty stuck with a similar issue, is there a way we get custom field values from multiple linked issues(not just first linked issue custom field value).
Thanks,
Vijay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Perfect!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.