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
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.