Using Scriptrunner to return custom field value

Hi

I'm trying to use Scriptrunner to (in part) get the value of a custom field. However, at the moment I am getting an error.

This is what I am trying to do, to get the value.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;

def issueManager = ComponentAccessor.getIssueManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

return getCustomFieldValue("Change Area")

When I do this, I get this error:

2017-11-21 12:30:12,374 ERROR [runner.ScriptFieldPreviewRunner]: ************************************************************************************* 2017-11-21 12:30:12,375 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: [Change Area] at Script160.run(Script160.groovy:9)

 

I am a complete noob, so apologies if I am making an obvious mistake. Can someone point out the error of my ways?

Best wishes

 

1 answer

1 accepted

This widget could not be displayed.
Alexey Matveev Community Champion Nov 21, 2017

Hello, 

You would need a script like this

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;

def issueManager = ComponentAccessor.getIssueManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("issuekey")
def csChangeArea = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Change Area")

return issue.getCustomFieldValue(csChangeArea)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 3 hours ago in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

15 views 0 1
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you