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
Accepted answer

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
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,304 views 5 11
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