Odd Groovy Script problem with a function call from another groovy script.

It worked once, and now it fails oddly enough.

I have script that calculates the percentage done by taking

(sum)timeSpent / ((sum)timeSpent +(sum)estimate)

My boss wants this to be a field and wants a second field that takes this information and multplies it by StoryPoints a number field we have to get the StoryPointsCompleted for an issue.

So I didn't want to duplicate my code so I have 3 groovy files

PercentRemaining the has method with this signature

public static double getPercentDone(Issue issue)

and PercentRemaingField

double percent = PercentRemaining.getPercentDone(issue)

if(percent == -1)
	return "<p>ERROR in PercentRemaing.groovy<p>"
else if (percent > 1.0)
	//Ids are just for Jira sorting to make 100.00% does not come before 10.00%
	return "<p id=\"a\">" + (percent * 100) + "%<p>"
	return "<p id=\"z\">" + (percent * 100) + "%<p>"

I have not made the 3rd file yet, but is almost the same thing it is going to access the custom field StoryPoints and multiply it by the double returned by my method.

It was working before but I was getting a rounding error (.989 became 1.0) and after that it just stopped working, even after I undid my few changes. (import java.math.RoundingMode and df.setRoundingMode(RoundingMode.DOWN); )

The files are in the same directory.

3 answers

This widget could not be displayed.
Henning Tietgens Community Champion Apr 24, 2013

Try to clear the Groovy class cache through the built-in scripts of Script Runner, maybe this helps.

Thaks, I will try that when I am in work next week. I just thought it was odd because it worked, and then all I did was added something to the function, tested it and it broke in the class that was calling it while working itself. (I had a sperate scripted field just for testing the function)

> The files are in the same directory

I'm not sure how you're calling the other scripts - using getFieldValue(firstCalcdField) should work, using other ways like calling static methods (which I see you're doing) seem a bit iffy to me.

Unfortunately the CustomField object itself doesn't seem to be in the script binding - otherwise I'd recommend just using the same file for all 3, and setting different output depending on the field name or ID.

What is the getFieldValue in? I tried this

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import java.lang.Double

def customFieldMag = ComponentAccessor.getCustomFieldManager()

double percent = (customFieldMag.getCustomFieldObjectByName( "%done" )).getValue(issue)

return percent

and I am getting nothing.

This widget could not be displayed.

I am stuck with this script: My requirement is

1) I need to connect to jira using groovy script calling from my terminal or from IntelliJIdea IDE .

2) Create issue and set summary and Description.

My Code is:

// 1) Creating Issues through IntelliJIdea

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import org.apache.log4j.Category

// Defninition of the component manager classes
def componentManager
def customFieldManager
def issueFactory
def jiraAuthenticationContext
def issueManager
def subtaskManager

def public CreateIssue(com.atlassian.jira.issue.MutableIssue issue)
componentManager = ComponentManager.getInstance()
customFieldManager = componentManager.getCustomFieldManager()
issueFactory = componentManager.getIssueFactory()
jiraAuthenticationContext = componentManager.getJiraAuthenticationContext()
issueManager = componentManager.getIssueManager()
subTaskManager =componentManager.getSubTaskManager()

def Category log = Category.getInstance("com.onresolve.jira.groovy.CM861");

//Creating a new Issue as subtask
MutableIssue createIssue = issueFactory.getIssue();

// 2) Setting Summary for the Issue Ticket on Creation by Default.

createIssue.setSummary("Issue Tickets From Groovy");
issue.setSummary("This is an issue ticket from Groovy")
println("I am in set Summary Method")

// 3) Setting Description for the Issue Ticket on creation by default

createIssue.setDescription("This is an issue ticket from Groovy");
println("I am in Set Description method")


// call to the Function


Henning can you please help me out with this.

Ask a new question - this is unrelated to the OP's question.

Henning Tietgens Community Champion Jun 13, 2013

And please use a code section for your code... it's not fun to read the code as normal text.

This widget could not be displayed.

sorry, from next time will use the source code section. i was totally unaware of it.

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
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

718 views 0 3
Read article

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