Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I acces a method in a custom class from a scripted field?

Marco Hödtke September 28, 2018

Jira version: 6.4.9

I have written a custom class in order to add some functionality and stored it to .../webapp/WEB-INF/classes/com/custom/Last24Hours.class. I am calling a method of the class from a scripted field and have tried the same from the script console. Here's the code:

package com.custom

def todaysDate = new Date()
def Created = issue.getCreated()
def Updated = issue.getUpdated()
def retVal = new String()
def last24Hours = new Last24Hours()

retVal = last24Hours.getChanges(todaysDate,Created,Updated)

return retVal

 I get the following error message:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script849.groovy: 7: unable to resolve class Last24Hours @ line 7, column 19. def last24Hours = new Last24Hours() 

^ 1 error

 I can access a .groovy script in the same location from a scripted field. What is wrong?

1 answer

0 votes
JP _AC Bielefeld Leader_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 29, 2018

Not sure, but don't you have to import Last24Hours somewhere?

Marco Hödtke October 1, 2018

It's in the same package. I've tried it, though, but this didn't work either:

package com.custom

import com.custom.Last24Hours

def todaysDate = new Date()
def Created = issue.getCreated()
def Updated = issue.getUpdated()
def retVal = new String()
def last24Hours = new Last24Hours()

retVal = last24Hours.getChanges(todaysDate,Created,Updated)

return retVal

This was executed from the script console. I got the following error message:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script853.groovy: 1: unable to resolve class com.custom.Last24Hours @ line 1, column 1. import com.custom.Last24Hours ^ 

1 error

Suggest an answer

Log in or Sign up to answer