It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner Script Field STopped Working After JIRA upgrade to 8.5.2 Edited

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
getCustomFieldValue(CustomField customField) 

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

CJ

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 Community Leader Dec 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]

@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 Community Leader Dec 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

@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 Community Leader Dec 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

@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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you