I’m trying to create a script runner script for a new scripted field that will calculate Weighted Shortest Job First (WSJF) which is a prioritization model used by SAFe. The script will get values from numeric fields and calculate a value based on those values – specifically ((Business Value + Time Criticality + Risk Oppty Value)/ Job Size). I’ve leveraged the work done on the following question https://community.atlassian.com/t5/Jira-questions/ScriptRunner-Groovy-getting-fields-and-adding-them-to-store-into/qaq-p/745252 but know something has to change to account for numeric values. Currently getting java.lang.NumberFormatException: For input string: "5.0" error. when I attempt to preview an issue with values. Any guidance is appreciated.
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField bvField = customFieldManager.getCustomFieldObject("customfield_10003");
CustomField tcField = customFieldManager.getCustomFieldObject("customfield_16149");
CustomField rrField = customFieldManager.getCustomFieldObject("customfield_16150");
CustomField jobSizeField = customFieldManager.getCustomFieldObject("customfield_16148");
String bvValue = issue.getCustomFieldValue(bvField).toString();
String tcValue = issue.getCustomFieldValue(tcField).toString();
String rrValue = issue.getCustomFieldValue(rrField).toString();
String jobSizeValue = issue.getCustomFieldValue(jobSizeField).toString();
int jobSizeInt = Integer.parseInt(jobSizeValue);
int rrInt = Integer.parseInt(rrValue);
int tcInt = Integer.parseInt(tcValue);
int bvInt = Integer.parseInt(bvValue);
def total = (bvInt + tcInt + rrInt) / jobSizeInt
return total
Jira number fields return Double type, so you may need to do a conversion as below
int rrInt = ((Double)rrValue).intValue()
But better option is as below
Double rrValue = (Double)issue.getCustomFieldValue(rrField);
int rrInt = rrValue.intValue()
Thank you! That worked out perfectly! Updated script:
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField bvField = customFieldManager.getCustomFieldObject("customfield_10003");
CustomField tcField = customFieldManager.getCustomFieldObject("customfield_16149");
CustomField rrField = customFieldManager.getCustomFieldObject("customfield_16150");
CustomField jobSizeField = customFieldManager.getCustomFieldObject("customfield_16148");
Double bvValue = (Double)issue.getCustomFieldValue(bvField);
Double tcValue = (Double)issue.getCustomFieldValue(tcField);
Double rrValue = (Double)issue.getCustomFieldValue(rrField);
Double jobSizeValue = (Double)issue.getCustomFieldValue(jobSizeField);
int jobSizeInt = jobSizeValue.intValue();
int rrInt = rrValue.intValue();
int tcInt = tcValue.intValue();
int bvInt = bvValue.intValue();
def total = (bvInt + tcInt + rrInt) / jobSizeInt
return total
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.