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?

1 answer

1 accepted

2 votes

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!

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,789 views 11 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot