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

Post upgrade from 6.4.9 to 7.0.11 groovy script is throwing errors Edited

We have have a groovy script which stops working post JIRA upgrade.


Can you please help us in fixing the same?


Error from logs


2017-05-02 15:21:17,766 devstatus.applink:thread-3 ERROR XXXXXXXXX 847x1378x2 1l6oimu /rest/dev-status/1.0/issue/summary [c.o.scriptrunner.customfield.GroovyCustomField] Script field failed on issue: XYZ-12345, field: Epic Rollup
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'abcd(abcd)' with class 'com.atlassian.jira.user.DelegatingApplicationUser' to class 'com.atlassian.crowd.embedded.api.User'
at Script159.getUser(Script159.groovy:121)
at Script159.retrieveIssuesInEpic(Script159.groovy:62)




import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;


import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;

import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.issue.DocumentIssueImpl;

import com.atlassian.jira.user.util.UserUtil;
import com.atlassian.crowd.embedded.api.User;

import java.util.concurrent.TimeUnit;

def logString="";

/* -----------------------------------------------------------------------------------------------------------
* Gobal vlaues: user, issue (assuming an Epic)
* ------------------------------------------------------------------------------------------------------------

/* User that will be used to search for issues.
* Must have Browse Project permission on all relevant projects.
USER = ‘abcd’
children = retrieveIssuesInEpic(issue)
total = sumOfOriginalEstimates(children)
total = format(total * 1000) // Atlassian returns milisecond K
return total.toString()

private format(millis) {
ApplicationProperties applicationProperties = ComponentManager.getComponentInstanceOfType(ApplicationProperties.class);
Integer daysPerWeek = applicationProperties.getDefaultBackedString(APKeys.JIRA_TIMETRACKING_DAYS_PER_WEEK).toInteger();
Integer hoursPerDay = applicationProperties.getDefaultBackedString(APKeys.JIRA_TIMETRACKING_HOURS_PER_DAY).toInteger();

// TODO clean up messy calcualtions, maybe use mod function?
Long long_hours = TimeUnit.MILLISECONDS.toHours(millis)
Integer int_days = long_hours.toInteger()/hoursPerDay
Integer int_hours = long_hours.toInteger() - (int_days * hoursPerDay)
Integer int_weeks = int_days/daysPerWeek
int_days = int_days - (int_weeks * daysPerWeek)
Long long_minutes = TimeUnit.MILLISECONDS.toMinutes(millis)
Integer int_minutes = long_minutes.toInteger() - (int_hours*60) - (int_days * hoursPerDay * 60) - (int_weeks * daysPerWeek * hoursPerDay * 60)

formatted = String.format("%d weeks, %d days, %d hours, %d minutes",
return formatted
private retrieveIssuesInEpic(epic) {
// Search for issues in epic
User user = getUser(USER);
jql_query = 'issueFunction in linkedIssuesOf("key = ' + epic.key + '", "is Epic of")'
if (user) {
List<DocumentIssueImpl> queryResults = runJQLSearch(user, jql_query);
if (queryResults && !queryResults.isEmpty()) {
return queryResults
return []

* Given a list of issues, sums up the original estimate on each.
private sumOfOriginalEstimates(issues) {
IssueManager issueManager = componentManager.getIssueManager();
Long sum = 0
for (Issue i in issues){
iObj = issueManager.getIssueObject(i.getId());
if (iObj) {
original_estimate = iObj.getOriginalEstimate()
if (original_estimate) {
sum += original_estimate
return sum

* Executes JQL search.
private List<DocumentIssueImpl> runJQLSearch(user, jqlQuery) {
SearchService searchService = ComponentAccessor.getComponent(SearchService.class);
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlQuery);
List<DocumentIssueImpl> queryResults;

if (parseResult && parseResult.isValid()) {
try {
SearchResults searchResult =, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
queryResults = searchResult.getIssues();

log.debug("Valid JQL: " + jqlQuery);
} catch (e) {
} else {
log.debug("Invalid JQL: " + jqlQuery);

return queryResults;

* Retrieves user object
private User getUser(user) {
UserUtil userUtil = ComponentAccessor.getUserUtil();
return userUtil.getUserObject(user);



1 answer

Looks like you're running into some issues centering around how the APIs around users changed. See

I'd recommend either changing your helper methods to take/return an ApplicationUser object or just use 'def'. 

For example:

private ApplicationUser getUser(user) {
    def userManager = ComponentAccessor.userManager

You may notice that I'm using the userManager instead of userUtil.getUserObject. That's simply because the getUserObject was deprecated in 7.0, but it will still work.

Suggest an answer

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

Jira Cloud for Google Sheets: Automatically Refresh Your Data!

Remember that time you realized it was possible to refresh your Jira data in Google sheets with just one click? What if we told you that you can now get the latest data with no clicks at all?! Zero! ...

265 views 3 9
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