Unable to set custom field value using custom script runner

Prerequisites : Set following script in script runner to update a custom field - timetracking_originalestimate using customfield_10204 and customfield_10205 average

import org.apache.log4j.Category
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.issuetype.IssueType
import com.atlassian.jira.issue.IssueImpl
import com.atlassian.jira.issue.IssueFactory
import com.atlassian.jira.issue.IssueKey
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.link.*
import com.atlassian.jira.security.*
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager


IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
CustomFieldManager cfManager = ComponentManager.getInstance().getCustomFieldManager();
MutableIssue issue = issueManager.getIssueObject(issue.id);
CustomField cforig = cfManager.getCustomFieldObjectByName("timetracking_originalestimate");
CustomField cfabp = cfManager.getCustomFieldObjectByName("customfield_10204");
CustomField cfhp = cfManager.getCustomFieldObjectByName("customfield_10205");

def abpEstimateValue = issue.getCustomFieldValue(cfabp);
def hpEstimateValue = issue.getCustomFieldValue(cfhp);
def orignalEstimateValue=issue.getCustomFieldValue(cforig);
def orignalEstimateValueModified=(Integer.parseInt(abpEstimateValue)+Integer.parseInt(hpEstimateValue))/2

IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
cforig.updateValue(null, issue, new ModifiedValue(orignalEstimateValue, orignalEstimateValueModified),changeHolder);

Step1 : Create issue in Jira
Expected output : timetracking_originalestimate filed should be updated
Actual Output : following error is coming and timetracking_originalestimate is not updated

  2014-08-24 15:01:20,352 http-bio-8080-exec-39 ERROR amehr1 901x35788x1 1pkqz7 14.140.116.145,172.18.13.241,172.18.14.165 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
2014-08-24 15:01:20,352 http-bio-8080-exec-39 ERROR amehr1 901x35788x1 1pkqz7 14.140.116.145,172.18.13.241,172.18.14.165 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Script post-function failed on ATTP-84: /data/jira_home/originalEstimatesCalculation.groovy
javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:103)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:212)
        at com.onresolve.jira.groovy.GroovyRunner.runFile(GroovyRunner.java:102)
        at com.onresolve.jira.groovy.GroovyRunner.run(GroovyRunner.java:62)
        at com.onresolve.jira.groovy.GroovyFunctionPlugin.execute(GroovyFunctionPlugin.java:38)
        at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1050)
        at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1446)
        at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:615)
        at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:848)
        at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:647)
        at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:583)
        at com.atlassian.jira.bc.issue.DefaultIssueService.create(DefaultIssueService.java:183)
        at com.atlassian.jira.bc.issue.DefaultIssueService.create(DefaultIssueService.java:148)  <+2> (DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.atlassian.plugin.osgi.hostcomponents.impl.DefaultComponentRegistrar$ContextClassLoaderSettingInvocationHandler.invoke(DefaultComponentRegistrar.java:129)
        at com.sun.proxy.$Proxy64.create(Unknown Source)  <+2> (DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at com.atlassian.plugin.osgi.bridge.external.HostComponentFactoryBean$DynamicServiceInvocationHandler.invoke(HostComponentFactoryBean.java:154)
        at com.sun.proxy.$Proxy64.create(Unknown Source)
        at com.atlassian.jira.quickedit.action.QuickCreateIssue.doExecute(QuickCreateIssue.java:266)  <+1> (ActionSupport.java:165)
        at com.atlassian.jira.action.JiraActionSupport.execute(JiraActionSupport.java:87)  <+7> (DefaultInterceptorChain.java:39) (NestedInterceptorChain.java:31) (ChainedInterceptor.java:16) (DefaultInterceptorChain.java:35) (GenericDispatcher.java:225) (GenericDispatcher.java:154) (JiraWebworkActionDispatcher.java:152)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)  <+2> (ApplicationFilterChain.java:305) (ApplicationFilterChain.java:210)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)  <+14> (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ChainedFilterStepRunner.java:87) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (XContentTypeOptionsNoSniffFilter.java:22) (AbstractHttpFilter.java:31) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (HeaderSanitisingFilter.java:44) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (IteratingFilterChain.java:46) (DelegatingPluginFilter.java:66)
        at com.atlassian.jira.tzdetect.IncludeResourcesFilter.doFilter(IncludeResourcesFilter.java:39)  <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
        at com.atlassian.jira.baseurl.IncludeResourcesFilter.doFilter(IncludeResourcesFilter.java:38)  <+8> (AbstractHttpFilter.java:31) (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66) (ContextFilter.java:25) (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
        at com.atlassian.servicedesk.internal.web.RedirectExternalCustomerToPortalFilter.doFilter(RedirectExternalCustomerToPortalFilter.scala:18)  <+4> (AbstractHttpFilter.java:31) (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
        at com.atlassian.mywork.client.filter.ServingRequestsFilter.doFilter(ServingRequestsFilter.java:37)  <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
        at com.atlassian.prettyurls.filter.PrettyUrlsDispatcherFilter.doFilter(PrettyUrlsDispatcherFilter.java:60)  <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
        at com.atlassian.prettyurls.filter.PrettyUrlsSiteMeshFilter.doFilter(PrettyUrlsSiteMeshFilter.java:92)  <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
        at com.atlassian.prettyurls.filter.PrettyUrlsMatcherFilter.doFilter(PrettyUrlsMatcherFilter.java:56)  <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
        at com.atlassian.labs.botkiller.BotKillerFilter.doFilter(BotKillerFilter.java:36)  <+23> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (ServletFilterModuleContainerFilter.java:77) (ServletFilterModuleContainerFilter.java:63) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (AccessLogFilter.java:103) (AccessLogFilter.java:87) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (XsrfTokenAdditionRequestFilter.java:54) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (SiteMeshFilter.java:181) (SiteMeshFilter.java:85) (SitemeshPageFilter.java:124) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ChainedFilterStepRunner.java:87) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (IteratingFilterChain.java:46) (DelegatingPluginFilter.java:66)
        at com.atlassian.prettyurls.filter.PrettyUrlsCombinedMatchDispatcherFilter.doFilter(PrettyUrlsCombinedMatchDispatcherFilter.java:61)  <+22> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (ServletFilterModuleContainerFilter.java:77) (ServletFilterModuleContainerFilter.java:63) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (SecurityFilter.java:234) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (TrustedApplicationsFilter.java:100) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (BaseLoginFilter.java:169) (JiraLoginFilter.java:70) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (IteratingFilterChain.java:46) (DelegatingPluginFilter.java:66) (OAuthFilter.java:61) (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
        at com.atlassian.bonfire.web.filters.BonfireP3PFilter.doFilter(BonfireP3PFilter.java:57)  <+3> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
        at com.atlassian.prettyurls.filter.PrettyUrlsCombinedMatchDispatcherFilter.doFilter(PrettyUrlsCombinedMatchDispatcherFilter.java:61)  <+13> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (ServletFilterModuleContainerFilter.java:77) (ServletFilterModuleContainerFilter.java:63) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ProfilingFilter.java:99) (JIRAProfilingFilter.java:19) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (AbstractJohnsonFilter.java:71) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210)
        at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
        at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
        at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)  <+10> (UrlRewriteFilter.java:394) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (GzipFilter.java:80) (GzipFilter.java:51) (JiraGzipFilter.java:55) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (IteratingFilterChain.java:46) (DelegatingPluginFilter.java:66)
        at com.atlassian.analytics.client.filter.AnalyticsFilter.doFilter(AnalyticsFilter.java:27)  <+4> (AbstractHttpFilter.java:31) (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (DelegatingPluginFilter.java:66)
        at com.atlassian.prettyurls.filter.PrettyUrlsCombinedMatchDispatcherFilter.doFilter(PrettyUrlsCombinedMatchDispatcherFilter.java:61)  <+40> (DelegatingPluginFilter.java:74) (IteratingFilterChain.java:42) (ServletFilterModuleContainerFilter.java:77) (ServletFilterModuleContainerFilter.java:63) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ChainedFilterStepRunner.java:87) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (AbstractCachingFilter.java:33) (AbstractHttpFilter.java:31) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (AbstractEncodingFilter.java:41) (AbstractHttpFilter.java:31) (PathMatchingEncodingFilter.java:49) (AbstractHttpFilter.java:31) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (JiraStartupChecklistFilter.java:78) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (MultipartBoundaryCheckFilter.java:41) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (ChainedFilterStepRunner.java:87) (JiraFirstFilter.java:57) (ApplicationFilterChain.java:243) (ApplicationFilterChain.java:210) (StandardWrapperValve.java:222) (StandardContextValve.java:123) (AuthenticatorBase.java:502) (StandardHostValve.java:171) (ErrorReportValve.java:100) (StandardEngineValve.java:118) (AccessLogValve.java:953) (CoyoteAdapter.java:408) (AbstractHttp11Processor.java:1041) (AbstractProtocol.java:603) (JIoEndpoint.java:310)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:724)
Caused by: javax.script.ScriptException: java.lang.NullPointerException
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318)
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111)
        ... 212 more
Caused by: java.lang.NullPointerException
        at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:1003)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
        at Script12.run(Script12.groovy:27)
        at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:315)
        ... 213 more

1 answer

This widget could not be displayed.

Time tracking is NOT a custom field. Start by fixing that.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 3 hours ago in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

15 views 0 1
Join discussion

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