post-function throws exception on issue.getCustomFieldValue(CustomField)

I am writing a post function to set the value of one customfield based on the value of another. Whenever I access issue.getCustomFieldValue(<some custom field>) , I get an exception.

I am running this post function on the "Create Issue" transition.

  • Creates the issue originally.
  • The value of field Customer Severity of the current issue will be set to the result of a Groovy expression (replacing existing values).
  • Fire a Issue Created event that can be processed by the listeners.

Code

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import org.apache.log4j.Category
import com.atlassian.jira.issue.customfields.option.Option
   
 
def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)
   
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();

log.debug "getting cfType" 
CustomField cfType = customFieldManager.getCustomFieldObject("customfield_12600")

 // also tried this with 'def cfValue'
Option cfValue = null;
if (null != cfType) {
	log.debug "got cfType with name=" + cfType.getFieldName()
	cfValue = (Option) issue.getCustomFieldValue(cfType) 
	log.debug "cfValue='" +  cfValue + "'"
}
else {
	log.debug "got null cfType"
}


Log Output
 
2014-07-22 12:33:55,035 http-bio-8080-exec-24 DEBUG bills 753x10883x1 1mhixyo 207.66.231.212,207.246.140.233 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.PostFunction] getting cfType
2014-07-22 12:33:55,035 http-bio-8080-exec-24 DEBUG bills 753x10883x1 1mhixyo 207.66.231.212,207.246.140.233 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.PostFunction] got cfType with name=Urgency
2014-07-22 12:33:55,037 http-bio-8080-exec-24 WARN bills 753x10883x1 1mhixyo 207.66.231.212,207.246.140.233 /secure/QuickCreateIssue.jspa [jmwe.plugins.functions.SetFieldValueFunction] Error while executing SetFieldValueFunction: groovy.lang.MissingMethodException: No signature of method: com.innovalog.jmwe.IssueProxy.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl) values: [Urgency]
groovy.lang.MissingMethodException: No signature of method: com.innovalog.jmwe.IssueProxy.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl) values: [Urgency]
	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
	at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
	at Script1.run(Script1.groovy:24)
	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:518)
	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:556)
	at groovy.lang.GroovyShell.evaluate(GroovyShell.java:527)
 
It's clear that the CustomField (it's radio-button valued) is getting fetched, but I can never access its value.  
 
Can you provide help?
 
Bill
 

7 answers

I run my existing script in the ScriptRunner console with one slight modification to create the issue context
issue = componentManager.getIssueManager().getIssueObject("PSUP-2506")


This script runs successfully, fetches the value of the custom field, and does not throw an exception.
0 vote

> jmwe.plugins.functions.SetFieldValueFunction

That's the jira misc workflows plugin. I think it also supports running groovy scripts or something, I've never looked to be honest. Stick with the original and the best.

So maybe you have an error in another function, not this one.

I appreciate the response, Jamie . My organization does use Jira Misc Workflows. I'm not the sole user/workflow in this environment, so removing this isn't an option.

Still looking for an answer to this question that will be compatible with Jira Misc Workflows.

0 vote

I would tag the question with that plugin's tag. Plugin owners usually will set up alerts, but only for questions with the right tags.

0 vote

Sorry I meant to post that on another question but I guess it's still relevant.

Done - thanks for your suggestion.

to get a field value use only "issue.get("CF")". To use the originally JIRA issue (com.atlassian.jira.issue.Issue), use "issue.issueObject"

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
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

477 views 6 11
Read article

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