Forums

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

Script runner is showing some errors but working, need to fix it to avoid re-indexing issue.

Sai Praveen Aminigadda April 7, 2020 edited

Hello,

 

we having a scripted field which can calculate the total time spent on each issue. which showing up some errors but working fine. but, looks like throwing some errors. when we tried to re-index, script runner those errors are blocking the re-index process and even after 24hours re-indexing is 0%. when we re-index after disabling script runner, it was done in 4-5 hours.

 

we found the errors of script runner and trying to fix them but unfortunately, script runner folks cannot join the call to resolve the issue and they take 48 hours to just make a reply comment on we're having a hard time fixing this script from more than a month.

any help to fix this script would be appreciated.

 

import com.atlassian.core.util.DateUtils
def resolvedNames = ["Resolved", "Closed"]
def timeDiff;
if (issue.getStatus().name in resolvedNames) {
timeDiff = issue.getResolutionDate().getTime() - issue.getCreated().getTime()
} else {
timeDiff = System.currentTimeMillis() - issue.getCreated().getTime()
}
return timeDiff/(1000*60*60)

2 answers

0 votes
Nic Brough -Adaptavist-
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.
April 9, 2020

What are the errors you are getting?

Sai Praveen Aminigadda April 10, 2020

Screenshot (823).png Screenshot (824).png Please check the attached screenshots.

Nic Brough -Adaptavist-
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.
April 11, 2020

This is one of my big arguments against weakly typed languages - the laziness and guesswork leads us to silly errors like this (this is NOT the fault of the coder, it's the coding language failing the human).  We gain ease of coding and prototyping, but lose way more time to worrying about conversions.

Here, groovy is guessing at a type.  This is a bad thing to do, but groovy has a lot of other good things, so we still quite like it.  If you make it explicit, and tell groovy to stop its painful guesswork, then it should work.  Try casting the last line to what Jira is expecting:

return (double) timeDiff/(1000*60*60)

From memory, that should work, but if not, it should give us a better error message to work with.

0 votes
Matt Doar
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 7, 2020

Delete the field from production.

Test the scripted field in your staging/test Jira instance


Your script is vulnerable to admin error where closing or resolving an issue didn't set the Resolution field

Sai Praveen Aminigadda April 8, 2020

If we delete, we will lose the data. since it is being used in hundreds of dashboards, we cannot delete. when I created the same field in staging with the same script, there are no errors. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
7.13.1
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Atlassian Community Events