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

This widget could not be displayed.

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...?

This widget could not be displayed.

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

487 views 3 18
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