How to copy a date custom field from parent to sub-task using groovy script?

Vishali
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.
July 22, 2013
I have a date custom field whose value should be copied over from parent to its sub-task using groovy script. Is there any reference that I can take a look?

2 answers

1 accepted

1 vote
Answer accepted
Eva
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.
July 24, 2013

few steps:

1) get the customfield id (you can check by going to the fields -> click on the custom field), the id is part of the URL (at least in JIRA 4.4)

2) For the code:

a) find the parent ticket (newIssue)

b) find the value by

def requestorFieldName = "customfield_XXXXX"

ComponentManager componentManager = ComponentManager.getInstance()   
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

//get Requestor Name
CustomField field = customFieldManager.getCustomFieldObject(fieldName)
requestorName = newissue.getCustomFieldValue(field)

c) and you can set the current issue with issue.setCustomFiedl (I think - best to look for JIRA API documentation)

Again this is based off JIRA 4.4, so you might need to double check the API documentation for whichever version you are using

Hope this helps!

Vishali
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.
July 26, 2013

Eva,

One of the date custom fields is causing a null pointer exception.

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:1095)
at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:943)
at com.atlassian.jira.issue.IssueImpl.setCustomFieldValue(IssueImpl.java:952)
at com.atlassian.jira.issue.MutableIssue$setCustomFieldValue.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:120)
at Script22.addSubTask(Script22.groovy:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

Eva
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.
July 26, 2013

can you paste the code here? It's hard to troubleshoot without seeing the full code...?

0 votes
Vishali
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.
July 26, 2013

Eva,

One of the date custom fields is causing a null pointer exception.

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:1095)
at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:943)
at com.atlassian.jira.issue.IssueImpl.setCustomFieldValue(IssueImpl.java:952)
at com.atlassian.jira.issue.MutableIssue$setCustomFieldValue.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:120)
at Script22.addSubTask(Script22.groovy:77)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1054)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:884)
at groovy.lang.DelegatingMetaClass.invokeMethod(DelegatingMetaClass.java:149)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl$2.invokeMethod(GroovyScriptEngineImpl.java:299)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145)
at Script22.run(Script22.groovy:449)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:315)

Do you have a clue on what this error is about?

Thanks,

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events