Set scrum board's Estimation Statistic to a custom numeric field

JamesT
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 3, 2017

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?

2 answers

1 accepted

3 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 3, 2017

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.

 

JamesT
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 3, 2017

Any way to do that without inserting a new post-function in every transition?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 3, 2017

I said listener.

JamesT
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 3, 2017

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? 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 3, 2017

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);

 

JamesT
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 3, 2017

Ah, that's working! smile

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");
}
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 3, 2017

Ah, yes, you have to set up a log object for scripts

 

 ...   = .().(....)
JamesT
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 3, 2017

That did it!  Thank for all the help!

0 votes
Dominik Haag March 20, 2018

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)

2018-03-20 12_41_11-000619.png

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)

2018-03-20 12_43_10-000620.png

 

Is there any way to force the Backlog view to update its cache? (Pressing F5 does not help)

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 20, 2018

I suspect you are not re-indexing the issue after the field update

Dominik Haag March 20, 2018

Thanks for that Info. What ist the best way to do this? Can you post an example on how to extend the code above?

M Vijay Kumar April 15, 2020

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. 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 15, 2020

No, people need to be able to use numeric fields for estimation.

Suggest an answer

Log in or Sign up to answer