It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

2 votes
Answer accepted
Thanos Batagiannis [Adaptavist] Community Leader Jun 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 Jun 13, 2017

Perfect, thanks.  Just what I was looking for.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Marketplace Apps & Integrations

Join our webinar: “Asset Management: The Role of Context in ITSM” with Atlassian & Riada

  Hi Atlassian Community! This is Teresa from the Jira Service Desk team. On June 19th, I’ll be hosting a webinar “Asset Management: The Role of Context in ITSM” with Atlassian Partne...

141 views 1 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you