Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scripted field to show name of Sprint on linked issue

Joleen Kantola September 2, 2018

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!

1 answer

1 accepted

0 votes
Answer accepted
Mark Markov
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.
September 3, 2018

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.

Joleen Kantola September 4, 2018

Thank you!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events