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

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

1 vote
Accepted answer

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

Perfect, thanks.  Just what I was looking for.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,389 views 0 8
Read article

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