I need to make the description containing a UserPicker custom field 10436 'Reports To' value and DatePicker custom field 10434 'Start Date' value. The current values in the ticket are 'Test User' which corresponds to username 'tuser' and '15/Mar/13'
issue.description = 'Reports To=' + cfValues['Reports To'] + '\nStart Date=' + cfValues['Start Date']
Output shows null in the description:
Reports To=null
Start Date=null
I want the output to be
Reports To=tuser
Start Date=15/Mar/13
Thanks
okay, found the answer in the response to https://answers.atlassian.com/questions/70050/why-do-i-get-a-null-pointer-exception-when-try-to-execute-a-post-function
The field that you want to take with you from the original issue is not also available to the cloned issue/project, the value will be null. You must make the fields available to both projects and issues of the original and clone issue. You DO NOT have to place the field on any screens.
Therefore, the following worked just fine, and the values where passed to the cloned ticket and placed (overwrote) the Descriptions field.
issue.summary = issue.summary + ' (separation ticket from HR)' issue.description = 'Reports To=' + cfValues['Reports To'] + '\nStart Date=' + cfValues['Start Date'] issue.assigneeId = 'sysadmin'
What context is this... some kind of post-function?
What happens if the user has entered a description, do you want to just overwrite it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, it is a post-function and yes, I want the description over written with the Reports To and Start Date information.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I also tried the below, but am getting:
javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException
import com.atlassian.jira.ComponentManager def componentManager = ComponentManager.instance def customFieldManager = componentManager.getCustomFieldManager() def rt = customFieldManager.getCustomFieldObjectByName('Reports To') def sd = customFieldManager.getCustomFieldObjectByName('Start Date') issue.description = 'Report To=' + issue.getCustomFieldValue(rt) +'\nStart Date=' + issue.getCustomFieldValue(sd)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Add some logging so you can see what exactly is null... could be one of the custom fields for instance/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can just add some log.warn() statements. You will add the logging statements to your code, rather than turn logging on from some other package.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Log Continued...
Caused by: java.lang.NullPointerException at com.atlassian.jira.issue.customfields.impl.DateCFType.getDefaultValue(DateCFType.java:128) at com.atlassian.jira.issue.customfields.impl.DateCFType.getDefaultValue(DateCFType.java:51) at com.atlassian.jira.issue.fields.CustomFieldImpl.getDefaultValue(CustomFieldImpl.java:1124) at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:942) at com.atlassian.jira.issue.Issue$getCustomFieldValue.call(Unknown Source) 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 Script25.run(Script25.groovy:10) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:315) ... 207 more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, I've moved a little farther. But still can't figure out how to pull the original issue value. I ran the below in Script Runner and it pulls the values correctly from the Issue.
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager() issueOld = ComponentManager.getInstance().getIssueManager().getIssueObject("HR-823") def cf = customFieldManager.getCustomFieldObject(10434) def sd = issueOld.getCustomFieldValue(cf) System.out.println(sd)
I modified my post function so I could hopefully see the output of the value in the logs, but it still has an problem.
import com.atlassian.jira.ComponentManager def componentManager = ComponentManager.instance def customFieldManager = componentManager.getCustomFieldManager() def cf1 = customFieldManager.getCustomFieldObject(10436) def cf2 = customFieldManager.getCustomFieldObject(10434) rt = issue.getCustomFieldValue(cf1) sd = issue.getCustomFieldValue(cf2) issue.summary = issue.summary + ' (separation ticket from HR)' System.out.println('Reports To=' + rt) System.out.println('Start Date=' + sd) issue.assigneeId = 'sysadmin'
My next comment will contain the log data
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Part 1 of log
2013-03-26 11:40:13,699 http-apr-8080-exec-20 ERROR klynch 700x6222x1 1oxtgcn 10.1.74.16 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function javax.script.ScriptException: javax.script.ScriptException: java.lang.NullPointerException at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233) at javax.script.ScriptEngine$eval.call(Unknown Source) at com.onresolve.jira.groovy.canned.utils.ConditionUtils.doAdditional(ConditionUtils.groovy:102) at sun.reflect.GeneratedMethodAccessor2147.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1770) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722) 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) ... 206 more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your println statements have gone to a different log... can you change the println to log.warn, and look for that output in the log.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I put the following, but catalina.out shows the same thing as before.
import com.atlassian.jira.ComponentManager def componentManager = ComponentManager.instance def customFieldManager = componentManager.getCustomFieldManager() def cf1 = customFieldManager.getCustomFieldObject(10436) def cf2 = customFieldManager.getCustomFieldObject(10434) rt = issue.getCustomFieldValue(cf1) sd = issue.getCustomFieldValue(cf2) issue.summary = issue.summary + ' (separation ticket from HR)' log.warn('Reports To=' + rt) log.warn('Start Date=' + sd) issue.assigneeId = 'sysadmin'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
changed to:
import com.atlassian.jira.ComponentManager def componentManager = ComponentManager.instance def customFieldManager = componentManager.getCustomFieldManager() def cf1 = customFieldManager.getCustomFieldObject(10436) def cf2 = customFieldManager.getCustomFieldObject(10434) rt = issue.getCustomFieldValue(cf1) sd = issue.getCustomFieldValue(cf2) issue.summary = issue.summary + ' (separation ticket from HR)' log.warn(rt) log.warn(sd) issue.assigneeId = 'sysadmin'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The log is 227 lines and 21410 characters, so I can't post it. But it's the same output as what I posted in the two posts above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.