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

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

This widget could not be displayed.

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?

I said listener.

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? 

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

 

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

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

 

 ...   = .().(....)

That did it!  Thank for all the help!

This widget could not be displayed.

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)

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

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

105 views 1 2
Join discussion

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