Groovy error

Sanu Soman
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.
March 18, 2014

Hi All,

I'm getting below error while capturing a value from custom field,

CustomField cf1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Deployments this week");
Option cf1Value=null;
cf1Value=(Option)issue.getCustomFieldValue(cf1, 1 as Double);
log.warn (cf1Value);

Error,

Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl, java.lang.Double) values: [Deployments this week, 1.0]
Possible solutions: getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField), setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object)
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318)
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111)
        ... 144 more
Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.getCustomFieldValue() is applicable for argument types: (com.atlassian.jira.issue.fields.CustomFieldImpl, java.lang.Double) values: [Deployments this week, 1.0]
Possible solutions: getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField), setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object)
        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.AbstractCallSite.call(AbstractCallSite.java:120)
        at Script15.run(Script15.groovy:33)
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:315)



Also try with,

CustomField cf1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Deployments this week");
Option cf1Value=null;
cf1Value=(Option)issue.getCustomFieldValue(cf1);
log.warn (cf1Value);

Error,

Caused by: javax.script.ScriptException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '0.0' with class 'java.lang.Double' to class 'com.atlassian.jira.issue.customfields.option.Option'
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318)
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111)
        ... 144 more
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '0.0' with class 'java.lang.Double' to class 'com.atlassian.jira.issue.customfields.option.Option'
        at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:360)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:599)
        at Script10.run(Script10.groovy:33)
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:315)
        ... 145 more

Any suggestions?

Thanks,

Sanu P Soman


					
				
			
			
			
				
			
			
			
			
			
			
		

1 answer

1 accepted

2 votes
Answer accepted
Boris Georgiev _Appfire_
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.
March 18, 2014

The second version of the script is okay as you call the right method, but you're casting to Option while the method returns Double. What is the type of this custom field ?

Sanu Soman
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.
March 18, 2014

custom field is number field

Boris Georgiev _Appfire_
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.
March 18, 2014

Why then are you casting to Option ? Just change the code like that:

Double cf1Value=null;
cf1Value=(Double)issue.getCustomFieldValue(cf1);

Sanu Soman
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.
March 18, 2014

Thanks a lot:)

Now value is "1.0" - Could you please tell me how I can remove ".0" from the value? (ie, want to skip the decimal part while capturing the value)

Boris Georgiev _Appfire_
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.
March 18, 2014

try trunc method:

cf1Value.trunc()

Suggest an answer

Log in or Sign up to answer