I'm trying to create a scripted field that shows the name of a Sprint on a linked issue. I've gotten the field to work with the following code, but there is a type checking error for "name" in the line shown in bold.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def linkedIssues = issueLinkManager.getOutwardLinks(issue.id)
CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11941")
if (customField != null) {
for (issueLink in linkedIssues) {
if (issueLink.issueLinkType.getOutward() == "Caused By") {
def linkedIssue = issueLink.destinationObject
return linkedIssue.getCustomFieldValue(customField).name[0]
}
}
}
return null
Is it okay to ignore the type checking error, or is there a better way to get the name of the Sprint?
Thank you!
Hello @Joleen Kantola
It is okay to ignore that error.
This is happens because getCustomFieldValue may returns different types of objects like ApplicationUser, Issue, Option etc. And compiler doesnt know what type exactly have this customfield, so it shows you error.
But in runtime it work with certain object and if this object has a method (name[0]) it will work.
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.