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

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 ?

custom field is number field

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

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

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)

try trunc method:

cf1Value.trunc()

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

692 views 6 13
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