Error on scripted field (illegal "as" cast)


I have this script that returns an error in JIRA log and is referred to in Scriptrunner support (

Can anyone direct me to the fix needed in this script?




import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.fields.FieldManager

import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.core.util.DateUtils


def fieldManager = ComponentAccessor.getCustomFieldManager() as FieldManager

def startCF = fieldManager.getCustomField("Downtime Start") as CustomField

def endCF = fieldManager.getCustomField("Downtime End") as CustomField

def startTime = startCF.getValue(issue) as Date

def endTime = endCF.getValue(issue) as Date

if (startTime == null || endTime==null) {return null}


return (endTime-startTime) / (60 * 1000) as Double

2 answers

This widget could not be displayed.

Try removing all the "as" statements.  You don't need them, as groovy handles the object types automatically.

image2016-8-15 15:53:14.png

image2016-8-15 15:54:6.png

Er, fieldManager doesn't have getCustomField as a function like that.


def myCustomField = com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("My Field")

There is an improvement, Thanks

can you look at the next issue?

image2016-8-15 16:11:37.png

Those two values are dates, not numbers.  As humans, we can make the intuitive leap from "Sunday - Wednesday = 3 days", but computers can't.  You might as well be asking it to do "apple - cat = ???".  Convert the dates to epoch time or something like that (epoch time is something like "number of milliseconds since base date")

This widget could not be displayed.

The same code doesn't produce any type checking errors for me - what version of the plugin are you using?

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

551 views 25 15
Join discussion

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