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>"
}
else
{
	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

1 vote
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.

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")
log.warn(createIssue.summary);



// 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")
log.warn(createIssue.description);


indexManager.reIndex(newSubtaskGV);
log.warn("***");
}


// call to the Function


CreateIssue(Issue)

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.

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 Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

39 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