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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Apr 10, 2018 in Marketplace Apps

Learn about how Stefan K. built one of the *first ever* Marketplace apps

In this post you will discover more about the evolution of K15t software, some big topics they're currently focusing on in the app space, and a rare (not not funny!) photo of founders Mike Cannon-Bro...

12,805 views 11 24
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