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

bill stratford July 22, 2014

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

0 votes
Guilherme Nogueira
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 22, 2015

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

0 votes
bill stratford August 7, 2014

Done - thanks for your suggestion.

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2014

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

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2014

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 votes
bill stratford August 6, 2014

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 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 22, 2014

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

0 votes
bill stratford July 22, 2014
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.

Suggest an answer

Log in or Sign up to answer