I want to determine the Story Points based on the selection of custom fields. The Custom Fields are drop-downs (text), so I need to assign a numeric value to each of the options. Then, I want to summarize the numeric values to set the Story Points total.
Here's what I have:
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.field.CustomFieldUpdatedEvent
import java.text.SimpleDateFormat
import com.atlassian.jira.datetime.DateTimeFormatterFactory
import com.atlassian.jira.datetime.DateTimeStyle
def customFieldManager = ComponentAccessor.getCustomFieldManager()
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def Story = getFieldByName("Story Points") //Grab the Story Points Field
def Impact = getFieldByName("Impact") //Grab the Impact Field
def Deliverable = getFieldByName("Deliverable") //Grab the Deliverables Field
def ImpactValue = Impact.getValue() // Grab the Value of the Impact Field
def DeliverableValue = Deliverable.getValue() // Grab the Value of the Deliverables Field
//Determine a Number based on the Impact Field Selection
if (ImpactValue.toString().contains("Low")) {
double ImpactSP = 1
}
else if (ImpactValue.toString().contains("Medium")) {
double ImpactSP = 2
}
else {
double ImpactSP = 3
}
//Determine a Number based on the Deliverables Field Selection
if (DeliverableValue.toString().contains("Document Only")) {
double DelSP = 0.5
}
else if (DeliverableValue.toString().contains("Sketch Only")) {
double DelSP = 0.5
}
else {
double DelSP = 1
}
Story.setFormValue(ImpactSP + DelSP)
I'm getting an error on the last line indicating the ImpactSP and DelSP variables are undeclared.
Oh, Behaviours are fun. The code part of this was actually fine (though I did modify the if statements a little). What was really needed was that this server side script had to be added to each field that contributed to the story point calculation. In my case, this was the "Impact" field and the "Deliverable" field.
Final server side script added to each field was this:
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.issue.field.CustomFieldUpdatedEvent;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
import com.onresolve.jira.groovy.user.FieldBehaviours;
import groovy.transform.BaseScript;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.user.util.UserManager;
import com.atlassian.jira.issue.MutableIssue;
@BaseScript FieldBehaviours fieldBehaviours
def Story = getFieldByName("Story Points") //Grab the Story Points Field
def Impact = getFieldByName("Impact") //Grab the Impact Field
def Deliverable = getFieldByName("Deliverables") //Grab the Deliverables Field
// Define the Values within each of the Fields Used
def ImpactValue = Impact.getValue()
def DelValue = Deliverable.getValue()
// Declare the Integer Variables
int newIntValue
int newDelValue
//Determine the Story Point Value based on the Impact Field Selection
if (ImpactValue.toString() == "Low") {
newIntValue = 1;
}
else if (ImpactValue.toString() == "Medium") {
newIntValue = 2;
}
else if (ImpactValue.toString() == "High") {
newIntValue = 3;
}
else {
newIntValue = 10; // This is a catch value
}
//Determine the Story Point Value based on the Deliverables Field Selection
if (DelValue.toString() == "Drawing Only" || DelValue.toString() == "Document Only") {
newDelValue = 1
}
else {
newDelValue = 10 // This is a catch value
}
// Total the values based on the selections
def total = newIntValue + newDelValue
//Set the Final Story Points Value
Story.setFormValue(total)
Hey @Kmmaughs
This previous Community post might be able to help. Set Story Points Field according to Single Select Field on same Issue
Another Community leader might have better scripting knowledge to assist you further.
Hope this helps a bit.
Thanks,
Brittany
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks. This made me think about it a little differently. I've cleared the error, but now the behavior is just not seemingly determining the value of the custom fields correctly.
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.field.CustomFieldUpdatedEvent
def customFieldManager = ComponentAccessor.getCustomFieldManager()
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def Story = getFieldByName("Story Points") //Grab the Story Points Field
def Impact = getFieldByName("Impact") //Grab the Impact Field
def Deliverable = getFieldByName("Deliverables") //Grab the Deliverables Field
def ImpactValue = Impact.getValue() as String // Grab the Value of the Impact Field
def DelValue = Deliverable.getValue() as String // Grab the Value of the Deliverables Field
int newIValue
int newDelValue
//Determine the Story Point Value based on the Impact Field Selection
log.debug("Impact is" + ImpactValue)
if (ImpactValue == "Low") {
newIValue = 1
}
else if (ImpactValue == "Medium") {
newIValue = 2
}
else if (ImpactValue == "High") {
newIValue = 3
}
else {
newIValue = 50
}
//Determine the Story Point Value based on the Design Deliverables Field Selection
if (DelValue == "Sketch Only" || DelValue == "Document Only") {
newDelValue = 1
} else {
newDelValue = 50
}
def total = newSysValue + newDelValue
Story.setFormValue(total)
I added in some large story points as a catch to see if the behavior cannot determine the string values of those custom fields, there was something defaulting. So now the Story Points field keeps getting set to 100 (at least it's summarizing them correctly). I don't know why the if statements aren't comparing the string values.
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.