Scriptrunner Script Field STopped Working After JIRA upgrade to 8.5.2

Hamdy Atakora December 30, 2019

Hello All,

Thanks in advance for the assistance on this. I have the following script field created in JIRA with Scriptrunner to return the content of our Program issue types.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.AbstractIssue
import com.atlassian.jira.issue.Issue

Issue issue = issue

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def baseurl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl")
def issueList = [:]
issueLinkManager.getInwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Program")
{
issueList.put(issueLink.getSourceObject().getKey(), issueLink.getSourceObject().getSummary()) }
}

//def customFieldManager = ComponentAccessor.getCustomFieldManager()
//def EpicLink = customFieldManager.getCustomFieldObjectsByName("Epic Link")
//def Epic = getCustomFieldValue(EpicLink)

def Epic = (AbstractIssue) getCustomFieldValue("Epic Link")

if (Epic) {
issueLinkManager.getInwardLinks(Epic.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Program")
{
issueList.put(issueLink.getSourceObject().getKey(), issueLink.getSourceObject().getSummary()) }
}
}
def programURLs = ""
issueList.each
{issueKey, issueSummary -> programURLs += "<a href=\"" + baseurl + "/browse/" + issueKey + "\">" + issueSummary + "</a><br/>" }
return programURLs

It was all working just fine until my last version of JIRA which is 7.13. After we recently upgraded. It stopped working. My code itself doesn't return any error but when i run it i get the following error

2019-12-30 11:16:08,263 ERROR [runner.ScriptFieldPreviewRunner]: ************************************************************************************* 2019-12-30 11:16:08,263 ERROR [runner.ScriptFieldPreviewRunner]: Script field preview failed for field that has not yet been created groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getCustomFieldValue() is applicable for argument types: (java.lang.String) values: [Epic Link] at Script45.run(Script45.groovy:21)

Please assist. Really cannot figure out what the issue is.

 

PS: For some reason code block will not work for me on this post. Sorry for the mess

1 answer

1 accepted

0 votes
Answer accepted
CJ Edwards December 30, 2019
getCustomFieldValue(CustomField customField) 

You have passed a String, which is not a CustomField type and therefor invalid.

CJ

Hamdy Atakora December 30, 2019

Hi @CJ Edwards  thanks for the reply. So what is the correction here ? I am not sure i fully understood the following

getCustomFieldValue(CustomField customField)
Payne
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.
December 30, 2019

@CJ Edwards is correct. What he means is that you need to create a CustomField object based upon the name of your field and pass that to getCustomFieldValue(), something like this:

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

CustomField requestedForField = customFieldManager.getCustomFieldObjectByName("Requested For")

ApplicationUser requestedForValue = (ApplicationUser)issue.getCustomFieldValue(requestedForField)

Note that getCustomFieldObjectByName() is deprecated, since there can exist more than one custom field with a given name. If you have only one field with that name, you can use this instead:

getCustomFieldObjectsByName("Requested For")[0]

Hamdy Atakora December 30, 2019

@Payne aaah i see. I followed your instructions and did it . I don't have any errors returning but the script field is still not returning its intended data when tested

Here is my code now 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.AbstractIssue
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.ApplicationUser;


//Issue issue = issue

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def baseurl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl")
def issueList = [:]
issueLinkManager.getInwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Program")
{
issueList.put(issueLink.getSourceObject().getKey(), issueLink.getSourceObject().getSummary()) }
}

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

CustomField EpicLink = customFieldManager.getCustomFieldObjectsByName("Epic Link")[0]

ApplicationUser Epic = (ApplicationUser)issue.getCustomFieldValue(EpicLink)


//def Epic = (AbstractIssue)issue.getCustomFieldValue(EpicLink)

if (Epic) {
issueLinkManager.getInwardLinks(Epic.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Program")
{
issueList.put(issueLink.getSourceObject().getKey(), issueLink.getSourceObject().getSummary()) }
}
}
def programURLs = ""
issueList.each
{issueKey, issueSummary -> programURLs += "<a href=\"" + baseurl + "/browse/" + issueKey + "\">" + issueSummary + "</a><br/>" }
return programURLs

Payne
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.
December 30, 2019

The ApplicationUser reference in my example is from my actual code, but you likely don't wish to cast to that class. You'll probably want to use your original line that is now commented that casts to an AbstractIssue.

Don't use this:

ApplicationUser Epic = (ApplicationUser)issue.getCustomFieldValue(EpicLink)

Use this:

def Epic = (AbstractIssue)issue.getCustomFieldValue(EpicLink)

Like CJ Edwards likes this
Hamdy Atakora December 30, 2019

@Payne  i have actually use the Abstract issue line as well and no errors but the field itself is still not returning the intended result. But yeah i have switched it to this 

def Epic = (AbstractIssue)issue.getCustomFieldValue(EpicLink)

Payne
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.
December 30, 2019

Hmm, one more thing that comes to mind is your use of getInwardLinks(); you could have that backward and not be getting any linked issues; you may instead need to use getOutwardLinks(). You may try dropping some log statements in there to see what all you're getting.

Something like:

import org.apache.log4j.Level
import org.apache.log4j.Logger


log = Logger.getLogger("com.onresolve.scriptrunner.runner.ScriptRunnerImpl")
log.setLevel(Level.DEBUG)


log.debug("In getInwardLinks()")
Like Hamdy Atakora likes this
Hamdy Atakora January 19, 2020

@Payne @CJ Edwards Thanks a lot for the help. This appear to be a bu with Scriptrunner

Suggest an answer

Log in or Sign up to answer