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

This widget could not be displayed.
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.
This widget could not be displayed.

> 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.

This widget could not be displayed.

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.

This widget could not be displayed.

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.

This widget could not be displayed.

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

This widget could not be displayed.

Done - thanks for your suggestion.

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

124 views 2 0
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