ScripRunner Dates Conflict

Harvey Bennett March 19, 2019

I have a custom field that is a type "Date". I am currently trying to update the field and its throwing me contradicting errors. It is expecting a type java.util.date in the updated field value area but then i get a series of errors with the first one saying that java.util.date is not supported. So I figured okay well then I will just create a string variable that is formatted like a 'date' variable. Then it throws me an error and says that it is expecting a java.util.date input. Does anyone have any ideas why it would be doing this? Jira version is 7.6.4. and ScriptRunner version is 5.4.28

 

This is the Groovy code I am testing with in Script Console:

SimpleDateFormat sf = new SimpleDateFormat("dd/MMM/yy");
Date dt = sf.parse(sf.format(new Date()));
log.warn(dt)
def myval = "13/Mar/19"

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cf1 = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Actual Start Date'};

def changeHolder = new DefaultIssueChangeHolder();
cf1.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf1), myval), changeHolder);

issue.store();

 

Current error message:

java.lang.String cannot be cast to java.util.Date

1 answer

1 accepted

0 votes
Answer accepted
Harvey Bennett March 19, 2019
issue = ComponentAccessor.getIssueManager().getIssueObject("ICB-128")
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def timestamp = new Timestamp(2013,3,23,1,2,3,9)

CustomField cf = customFieldManager.getCustomFieldObjectByName("Actual Start Date"); // Date Field
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), timestamp),changeHolder);
Harvey Bennett March 19, 2019

It is expecting a timestamp format based off other answers I finally stumbled on in the community.  https://community.atlassian.com/t5/Answers-Developer-Questions/How-can-i-update-custom-field-values-Numbers-field-DatePicker/qaq-p/504078

Vijay near the bottom shows how to work with every field type. Very useful

Suggest an answer

Log in or Sign up to answer