Update a Jira Date Time Picker field without history

Normann P_ Nielsen _Netic_
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.
June 26, 2024

 

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


As in:

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


But I cant get a date into the field:


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


-----

Code:


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

Error:


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


2 answers

2 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 27, 2024

Hi @Normann P_ Nielsen _Netic_

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

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

Normann P_ Nielsen _Netic_
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.
June 27, 2024

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

0 votes
Answer accepted
Normann P_ Nielsen _Netic_
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.
June 26, 2024

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events