groovy post function clone and set datepicker customfield

I'm having issues setting a custom datepicker field from the groovy post function Clones an issue and links.

Condition: blank

Target Project: Different Project name

Target Issue Type: New Issue Type

Additional issue actions:

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Start Date'}
issue.setCustomFieldValue(cf.id, '2012-09-17 00:00:00.0')

Issue Link Type: New Plan

Log error:

Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setCustomFieldValue() is applicable for argument types: (java.lang.String, java.lang.String) values: [customfield_10434, 2012-09-17 00:00:00.0]
Possible solutions: setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object), getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField)

I've also tried

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Start Date'}
issue.setCustomFieldValue(cf.id, '30/Apr/13')

Log error:

Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setCustomFieldValue() is applicable for argument types: (java.lang.String, java.lang.String) values: [customfield_10434, 30/Apr/13]
Possible solutions: setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object), getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField)

The server shows the date picker field as DD/MMM/YY when being filled out.

I'm using version script runner 2.1.3

3 answers

1 accepted

Accepted Answer
1 vote

Thanks Jamie,

import java.sql.Timestamp
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Start Date'}
issue.setCustomFieldValue(cf, new Timestamp(new Date(2012,9,17).getTime()))

That worked. I was able to construct my final piece of getting a different date picker field to populate to a different date picker field by putting the following.

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Start Date'}
issue.summary = 'Equipment Order (automatic ticket)'
issue.setCustomFieldValue(cf, cfValues['Effective Date'])

oh Jamie, if you could convert one of your comments to answer, I'll accept it. Thanks

And thanks to Henning for your assist

1 vote
Henning Tietgens Community Champion May 01, 2013

I think you have to use a Timestamp (or Date) object as value to set. You can easily see the needed object if you call getValue() on the customfield an examine the returned object.

log.error cf.getValue(issue).class.name

If you now look into the log you will see the needed object for setting the value.

Henning

alright, I 'think' that it is saying it needs a timestamp. I ran the following through the script runner at the ticket in question.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager

CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
issueOld = ComponentManager.getInstance().getIssueManager().getIssueObject("HR-823")
def cf = customFieldManager.getCustomFieldObjectByName("Start Date")
def rt = issueOld.getCustomFieldValue(cf)

log.error cf.getValue(issueOld).class.name
rt

and it came back with this in the log

Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.sql.Timestamp.getValue() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl) values: [HR-823]
Possible solutions: getDate(), getClass(), getDay(), getTime(), getNanos(), getTime()

and this value on the output

2012-09-17 00:00:00.0

I also dumbied down my 'Additional Issue Actions' to

issue.setCustomFieldValue("customfield_10434", '2012-09-17 00:00:00.0')

and I get this in the log

javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setCustomFieldValue() is applicable for argument types: (java.lang.String, java.lang.String) values: [customfield_10434, 2012-09-17 00:00:00.0]
Possible solutions: setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object), getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField)

I also tried

issue.description = '\nStart Date=' + cfValues['Start Date'] + '='

to make sure the output didn't have any hidden characters or spaces. Output was

Start Date=2013-04-30 00:00:00.0=

As you can see the output is the same format as the value I'm trying to set.

Henning Tietgens Community Champion May 01, 2013

I cannot reproduce your ScriptExecption, for me your script works well.

But, you have to use a Date object for setting. Currently you are using a String.

Try

new Date(2012,9,17)

as value for setCustomFieldValue()

Henning

I tried

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Start Date'}
new Date(2012,9,17)
issue.setCustomFieldValue(cf.id, Date)

and I got

Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setCustomFieldValue() is applicable for argument types: (java.lang.String, java.lang.Class) values: [customfield_10434, class java.util.Date]
Possible solutions: setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object), getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField

Henning Tietgens Community Champion May 01, 2013
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Start Date'}
issue.setCustomFieldValue(cf.id, new Date(2012,9,17))

Try this.

First off, I REALLY appreciate your help on this. I put that in and got

Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setCustomFieldValue() is applicable for argument types: (java.lang.String, java.util.Date) values: [customfield_10434, Thu Oct 17 00:00:00 PDT 3912]
Possible solutions: setCustomFieldValue(com.atlassian.jira.issue.fields.CustomField, java.lang.Object), getCustomFieldValue(com.atlassian.jira.issue.fields.CustomField)

Henning Tietgens Community Champion May 01, 2013

You're welcome :-)

Oh, I see.. you have to use the customfield itself for setCustomFieldValue() and not the Id of the customfield. So try

issue.setCustomFieldValue(cf, new Date(2012,9,17))

Henning

tried your code and got

Caused by: org.ofbiz.core.entity.GenericEntityException: while inserting: [GenericEntity:CustomFieldValue][id,6924947][datevalue,Thu Oct 17 00:00:00 PDT 3912][issue,605122][parentkey,null][customfield,10434] (Java type java.util.Date not currently supported. Sorry.)

produced this log entry

Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script2.groovy: 2: unable to resolve class Timestamp 
 @ line 2, column 31.
   issue.setCustomFieldValue(cf, new Timestamp(new Date(2012,9,17).getTime()))
                                 ^

the '^' is pointing at the 'new' of 'new Timestamp'

import java.sql.Timestamp

Henning Tietgens Community Champion May 02, 2013

Thanks Jamie for pitching in (and for your vote) while I was enjoying my leisure time.. :-)

1 vote

Try this:

import java.sql.Timestamp

issue.setCustomFieldValue(cf, new Timestamp(new Date(2012,9,17).getTime()))

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 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...

27,272 views 2 7
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