JIRA Java API | Update Date/Time picker

Hi All,

I am trying to update a Date/Time picker customfield, using JAVA.If I do code something as simple, as:

Object dateCustomField = issue.getCustomFieldValue((CustomField)ComponentAccessor.getCustomFieldManager().getCustomFieldObject(new Long(10391)));

updateValue(dateCustomField, issue, "2013-10-25 01:37:00.0");

An error is thrown in the logs:

java.lang.ClassCastException: java.sql.Timestamp cannot be cast to com.atlassian.jira.issue.fields.CustomField.

My question is: How can I update a Date/Time picker CF? I can not find any working documentation for JIRA 5.2.

I hope someone can help.

Cheers.

3 answers

1 accepted

2 votes

What are you doing in updateValue? Make sure you pass a Timestamp object instead of CustomField.

1 votes
Henning Tietgens Community Champion Oct 20, 2013

The object parameter should be a Timestamp, which is a Date. So you first have to create a valid Timestamp object an pass this to updateValue().

Hi,

Thank you for your answers. I am not sure if I fully understand the approach. If I give a TS as a parameter, it won't compile, so I expect that I miss something.

I have found another approach on this page: https://answers.atlassian.com/questions/164789/groovy-post-function-clone-and-set-datepicker-customfield, but it doesn't update the value. It also does not throw errors in the logs.

MutableIssue mu = (MutableIssue) issue;
CustomField cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(new Long(10391));
mu.setCustomFieldValue(cf, new Timestamp(new Date(2012,9,17).getTime()));
mu.store();
Henning Tietgens Community Champion Oct 21, 2013

You have to use IssueManager.updateIssue() and not MutableIssue.store() to store customfield changes. store() only saves direct members of the issue like summary.

The class of the object you pass with setCustomFieldValue must be the same as the class of the object you get from getCustomFieldValue for the same customfield.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,802 views 11 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot