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

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

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!

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)

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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

86 views 0 5
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