groovy post function clone and set datepicker customfield

Kevin Lynch May 1, 2013

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

1 vote
Answer accepted
Kevin Lynch May 2, 2013

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'])

Kevin Lynch May 2, 2013

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
JamieA
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.
May 2, 2013

Try this:

import java.sql.Timestamp

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

1 vote
Henning Tietgens
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.
May 1, 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

Kevin Lynch May 1, 2013

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
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.
May 1, 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

Kevin Lynch May 1, 2013

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
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.
May 1, 2013
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Start Date'}
issue.setCustomFieldValue(cf.id, new Date(2012,9,17))

Try this.

Kevin Lynch May 1, 2013

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
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.
May 1, 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

Kevin Lynch May 1, 2013

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

Kevin Lynch May 2, 2013

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'

JamieA
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.
May 2, 2013

import java.sql.Timestamp

Henning Tietgens
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.
May 2, 2013

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

Suggest an answer

Log in or Sign up to answer