Update a Jira Date Time Picker field without history
Asked by Normann P_ Nielsen _Netic_:

According to:

https://community.atlassian.com/t5/Jira-questions/Update-System-Field-Without-Updating-History/qaq-p/1745173 the thing to use is:

CustomField.updateValue

<br />

As in:

https://library.adaptavist.com/entity/update-custom-fields-without-change-history

<br />

But I cant get a date into the field:

<br />

customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), fieldValue), new DefaultIssueChangeHolder())

For fieldValue I have tried:

Code:

def fieldValue = New Date()

Error:

{"message":"Java type java.util.Date not currently supported. Sorry.","stack-trace":"java.lang.IllegalArgumentException: Java type java.util.Date not currently supported. Sorry.\\n\\tat org.ofbiz.core.entity.jdbc.SqlJdbcUtil.getFieldType(SqlJdbcUtil.java:907)\\n\\tat org.ofbiz.core.entity.jdbc.SqlJdbcUtil.setValue(SqlJdbcUtil.java:798)\\n\\tat org.ofbiz.core.entity.jdbc.SqlJdbcUtil.setValue(SqlJdbcUtil.java:767)\\n\\tat

<br />

-----

Code:

<br />

Date fieldValue1 = new Date()  
fieldValue = fieldValue1.getTime()

Error:

<br />

"message":"class java.lang.Long cannot be cast to class java.util.Date (java.lang.Long and java.util.Date are in module java.base of loader 'bootstrap')","stack-trace":"java.lang.ClassCastException: class java.lang.Long cannot be cast to class java.util.Date (java.lang.Long and java.util.Date are in module java.base of loader 'bootstrap')\\n\\tat com.atlassian.jira.issue.customfields.impl.DateTimeCFType.getDbValueFromObject(DateTimeCFType.java:61)\\n\\tat

----

Due to  
https://bitbucket.org/alex1mmm/scriptrunner/src/b637e102aacd9a21ba20a7eaef2437a3e8979eb6/articles/updateissue/updateValue?at=master\&fileviewer=file-view-default is seems that the getTime() - long shoudl work...

<br />


Answers:
author: Ram Kumar Aravindakshan _Adaptavist_
body: Hi [@Normann P_ Nielsen _Netic_](/t5/user/viewprofilepage/user-id/664692)

Your approach will not work because it needs the java.sql.Date and not the java.util.Date.

Below is a sample working code for your reference:-  

```
import com.adaptavist.hapi.jira.issues.Issues
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.index.IssueIndexingParams
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import java.sql.Date

def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
def customFieldManager = ComponentAccessor.customFieldManager

def issue = Issues.getByKey('MOCK-3') as MutableIssue

def customField = customFieldManager.getCustomFieldObjectsByName('Date Time Sample').first()
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), new Date(System.currentTimeMillis())), new DefaultIssueChangeHolder())

issueIndexingService.reIndex(issue, IssueIndexingParams.INDEX_ISSUE_ONLY)
```

Please note that the sample working code above is not 100% exact to your environment. Hence, you must make the required modification.

The code has been tested on the ScriptRunner console.

Below is a screenshot of the result for your reference:-

![update_date_time_field.png](https://community.atlassian.com/t5/image/serverpage/image-id/332076i83BFF4CDC9AB48F6/image-size/large?v=v2&px=999 "update_date_time_field.png")

In the screenshot above, you can see that the Date Time Sample field is updated but no history is added.

I hope this helps to solve your question. :-)

Thank you and Kind regards,  
Ram

comments: author: Normann P_ Nielsen _Netic_
body: AS posted yesterday, I found the solution in <https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Java-type-java-util-Date-not-currently-supported-Sorry/qaq-p/592502>

to use .toTimeStamp() instead of .getTime()


author: Normann P_ Nielsen _Netic_
body: <https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Java-type-java-util-Date-not-currently-supported-Sorry/qaq-p/592502>


Tags: data-center

groovy

jira-data-center

jira-server

script

scriptrunner

server