I've traditionally used ScriptRunner to do these operations but I'm finding it not functional for my specific use-case. Instead, I am trying to use JMCF to iterate through specific subtasks and sum up a field's values.
This is my code, but I get the following error:
<!-- @@Formula: import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.fields.CustomField; IssueManager issueManager = ComponentAccessor.getIssueManager(); CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); final CustomField customFieldObject = customFieldManager.getCustomFieldObject("customfield_11811"); if(customFieldObject == null){ return null; } double total = 0; if (issue != null) { Collection<Issue> subTaskObjects = issue.getSubTaskObjects(); if(subTaskObjects != null && subTaskObjects.size() != 0){ for (Issue subTaskObject : subTaskObjects) { if (subTaskObject.issueTypeObject.name == "Specific Subtask") { private Object value = customFieldObject.getValue(subTaskObject); total += value; } } return total; } else{ return null; } } return null; -->
ERROR [com.innovalog.jmcf.fields.CalculatedNumberField] CalculatedNumberField: error evaluating formula: Parse error at line 17, column 46. Encountered: =
ERROR [com.innovalog.jmcf.fields.CalculatedNumberField] CalculatedNumberField: error evaluating formula: Sourced file: inline evaluation of: `` import com.atlassian.jira.component.ComponentAccessor; import com.atlassian. . . . '' : Typed variable declaration : Final variable, can't re-assign.
I've just been pulling these with JAVAMelody for now.
I don't encounter these errors in ScriptRunner so I am assuming that the BeanShell library just doesn't support as much JAVA as scriptrunner does. But I don't seem to be able to figure out my issue, so I'm poking around for some help. Thanks in advanced.
My updated code. This is not throwing errors, but also only is returning null. I am not sure if this because customfield11811 is a calculated field of it's own or not.
<!-- @@Formula: import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.fields.CustomField; IssueManager issueManager = ComponentAccessor.getIssueManager(); CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); CustomField customFieldObject = customFieldManager.getCustomFieldObject("11811"); if(customFieldObject == null){ return null; } double total = 0; if (issue.equals == null) { Collection<Issue> subTaskObjects = issue.getSubTaskObjects(); if(subTaskObjects = null && subTaskObjects.size() = 0){ for (Issue subTaskObject : subTaskObjects) { if (subTaskObject.issueTypeObject.name.equals("Specific Subtask")) { Object value = customFieldObject.getValue(subTaskObject); total += value; } } return total; } else{ return null; } } return null; -->
BeanShell is close to Java, but ScriptRunner uses Groovy, which is a language on its own.
First of all, get rid of the "private" keyword. Then, don't use "==" to compare strings, use ".equals()" instead. Also, I'm not sure the "final" keyword is supported.
Thanks David, I've been in the BeanShell docs but I'm still picking up the nuances. I seem to have pasted the wrong copy, I was _only_ using "final", not "private" in my test instance. The new version is not erroring out at all! But it's still null. Back to check my logic. New question: Can I calculate a field based on other calculated fields?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
getCustomFieldObject(
"11811"
) should read
getCustomFieldObject(
"customfield_11811"
)
In general, you can use the log object to write to the JIRA log file: log.error("some text");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the hints, "you've been helpful" doesn't do it justice. My latest snafu is "Collection<Issue> subTaskObjects.equals(issue.getSubTaskObjects());" It doesn't seem to like the "<" ">" symbols. :p
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's right, BeanShell doesn't support Generics.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You've been a great help David. Thank you for the excellent add-ons, we regularly use them with customers. I am currently solving this problem with a mix of ScriptRunner and JMCF, but as time allows I'll finish this code and move completely to your add-on, so I can have a single solution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.