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