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.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ask a new question - this is unrelated to the OP's question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And please use a code section for your code... it's not fun to read the code as normal text.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.