You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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 )) {
days++;
}
date = date + 1;
date_aux = date.format('yyyy-MM-dd');
i++;
}
LeadTimeField.setFormValue(days)
Much appreciated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.