Java type java.util.Date not currently supported. Sorry.

Roy Chapman May 31, 2017

I am trying to set a custom date field in JIRA in a post function, using the Script Runner.  A snippet of the code below.  This tries to create an "SLA Date" of 5 working days from now (this is a claculated field from previous code, I have tried to keep the snippet to a minimum.  When it executes I get the message "Java type java.util.Date not currently supported. Sorry.".  It is evidently the final line that is failing.

My questions

Is this the correct way to set a date field (I have tried Date and Data and Time types)?

The section to increment the date by 5 days comes from the another answer.  is this correct?

sla = 5

Date result = today;
def newDate

int i = 0 ;
while (i < sla) {
result = result + 1
newDate = new Date(result.getTime())
if (newDate[Calendar.DAY_OF_WEEK] == Calendar.SATURDAY || newDate[Calendar.DAY_OF_WEEK] == Calendar.SUNDAY) {
sla ++;
}

i ++;
}

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("SLA Date")

issue.setCustomFieldValue(cf, newDate)

 

1 answer

1 accepted

5 votes
Answer accepted
Thanos Batagiannis _Adaptavist_
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 12, 2017

Hi Roy,

The logic seems right, if you want to skip weekends. 

The only thing you have to change is the last line and I repost your code with few minor changes

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def issue = issue as MutableIssue
def sla = 5, i = 0
Date result = new Date(), newDate

while (i < sla) {
    result = result + 1
    newDate = new Date(result.getTime())
    if (newDate[Calendar.DAY_OF_WEEK] == Calendar.SATURDAY || newDate[Calendar.DAY_OF_WEEK] == Calendar.SUNDAY) {
        sla ++
    }

    i ++
}

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("First DateTime")

// the date field expects a Timespamp issue.setCustomFieldValue(cf, newDate.toTimestamp())

Please let me know if this does the trick.

Kind regards, Thanos

Roy Chapman June 13, 2017

Perfect, thanks.  Just what I was looking for.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events