After getting a custom scripted field working (see https://answers.atlassian.com/questions/45825747), we want to set that field as the Estimation Statistic on an agile board. However, this scripted field is not available in the Estimation Statistic drop-down list (in the board's config screen). Other custom fields show up in the drop-down list.
Is it possible to use scripted fields in the Estimation Statistic? If not, is there another way (like using a script) to set the value of another field, and use that field as the Estimation Statistic?
JIRA Software's board only recognises the timetracking and standard numeric fields as valid estimation statistics. A script runner field is not a standard numeric field, so it won't see it.
You are, however, spot-on with your idea. Create a normal numeric field, place it only on the issue view screen (not create or edit), and then write a listener to populate it when an issue is updated. You can pretty much reuse the calculation code for the scripted field to do it.
Any way to do that without inserting a new post-function in every transition?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I said listener.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, haven't written a listener before, but I get the idea. But, the scripted-field script:
import com.atlassian.jira.issue.Issue; import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.component.ComponentAccessor; def field = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Level of Effort") def effortText = issue.getCustomFieldValue(field).toString(); if (effortText == "XS") { return 1 } else if (effortText == "Small") { return 2 } else if (effortText == "Medium") { return 3 } else if (effortText == "Large") { return 4 } else if (effortText == "XL") { return 5 } else { return null }
obviously won't work as-is. Instead of returning a value, the listener needs to set the value of another field. I assume I can easily do that, similar to how I'm getting the value of the "Level of Effort" field. But, "issue" on line 7 is not defined, so there must be another way to refer to the current issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, the "issue event" the listener picks up will contain it.
From memory, you should be able to use just "event". So
event.issue.getCustomFieldValue(field).toString();
The bit I am a little more hazy on is setting the value. I think you need something like the post-function code for amending a field:
I've called the numeric custom field "Effort number field", and assumed your existing code just sets a numeric variable called effortNumber instead of doing the "return x"
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def targetField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name ==
"Effort number field"
}
def changeHolder =
new
DefaultIssueChangeHolder();
Issue issue = event.issue;
targetField.updateValue(
null
, issue,
new
ModifiedValue(issue.getCustomFieldValue(targetField),
effortNumber
),changeHolder);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, that's working!
Debugging was made MUCH harder though as none of these log.info/log/debug statements show up in the JIRA log nor in the log window associated with the script's pass/fail status (3 of the past 15 executions failed).
Is there any easier way to debug?
import com.atlassian.jira.issue.Issue; import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.MutableIssue; log.debug "EDA Listener step 1"; def field1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Level of Effort") def field2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Level of Effort (numeric)") def effortText = event.issue.getCustomFieldValue(field1).toString(); log.info("EDA Listener step 2"); log.info(effortText); double number = 0; if (effortText == "XS") { number=1 } else if (effortText == "Small") { number=2 } else if (effortText == "Medium") { number=3 } else if (effortText == "Large") { number=4 } else if (effortText == "XL") { number=5 } log.debug "EDA Listener step 3"; log.debug number; if (number > 0) { log.info("EDA Listener Updating issue...") def changeHolder = new DefaultIssueChangeHolder(); field2.updateValue(null, event.issue, new ModifiedValue(event.issue.getCustomFieldValue(field2), number),changeHolder); } else { log.info("No Level of Effort detected"); }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, yes, you have to set up a log object for scripts
import org.apache.log4j.Category
def Category log = Category.getInstance("onresolve.jira.groovy.GroovyListener")
log.setLevel(org.apache.log4j.Level.DEBUG)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That did it! Thank for all the help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It faced the same problem and tried to solve it with the solution described here.
I have a custom field (Dropdown) with T-Shirt-Sizes for Estimation. The T-Shirt-Sizes are recalculated in a Listener (as described above) to fill a numeric custom field.
In the Issue view that works fine and the value is updated correctly when changing the T-Shirt Size.
But it seems that the values displayed in the Backlog (Estimation Field) seems to be cached somewhere. There always the last Value ist displayed, but never the current. It seems that the Backlog view is not notified about the scripted update of the value.
Example:
1. Change the T-Shirt Size to S so that the resulting Number is 7 --> Issue Details view shows 7 (OK); Backlog shows Estimate of 0 (ERROR)
2. Change the T-Short Size to XL so that the resulting Number is 25 --> Issue Details view shows 25 (OK); Backlog shows Estimate of 7 (Error)
Is there any way to force the Backlog view to update its cache? (Pressing F5 does not help)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I suspect you are not re-indexing the issue after the field update
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for that Info. What ist the best way to do this? Can you post an example on how to extend the code above?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't want my number Custom fields to be populated in Estimation Statistic as they are used for other purposes. Is there a way I can restrict them so that Users won't confuse on the same.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, people need to be able to use numeric fields for estimation.
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.