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

1 vote
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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

111 views 0 3
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