Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

ScriptRunner Behaviour - Cast Problem (String vs. Date)

I'm using the code below in a ScriptRunner Behaviour to calculate lead time in working days based on today's date and the "Start Date" date picker custom field. No errors are shown in the Behaviours console and it seems to work. However there are repeated errors in the JIRA logs which read: groovy.runtime.typehandling.GroovyCastException: Cannot cast object '' with class 'java.lang.String' to class 'java.util.Date'

Can someone help explain why this is happening and what I can do to resolve it? I've tried several other approaches but all of them flag different but related errors directly within the Behaviours console and won't validate.

import java.util.Date.*
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor

def StartDateField = getFieldByName("Start Date")
def LeadTimeField = getFieldByName("Lead Time (Days)")

def date_start = new Date()
def date_end = StartDateField.getValue() as Date

def date_limit = date_end.format('yyyy-MM-dd');
def date_aux = date_start.format('yyyy-MM-dd');
def date = date_start;
def i = 0;
def days = 0;
def weekday = null;
while ( date_aux != date_limit ) {
weekday = Date.parse('yyyy-MM-dd', date_aux)[Calendar.DAY_OF_WEEK];
if (!( weekday == Calendar.SUNDAY || weekday == Calendar.SATURDAY )) {
date = date + 1;
date_aux = date.format('yyyy-MM-dd');


 Much appreciated.

1 answer

Can anyone help me figure this out, please?

Have you found any solution for this? I get a similar error message

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Comparison between Zephyr & Xray

I am sharing this article with both Zephyr and Xray information and everything should be in one place. It will be easy to know when selecting Zephyr or Xray. Zephyr and Xray are both Jira plug-ins u...

180 views 1 5
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