Hi,
I need some help with the groovy script. First of all, I honestly don't know much about the groovy script. I play around with it by looking online. One of my coworkers helped me with this script below but he left the company. I need some help in updating this to fix the error.
I have two fields:
- Story points (number field)
- Priority Field (single select dropdown field with options)
- 1 - Roadmap/Critical
- 2 - Urgent
- 3 - Needed
- 4 - Nice to have
- 5 - Want
The goal of this script is to calculate a value based on = Priority Field/Story Points.
The script works when there are values entered for both the story points and priority fields but it gives null with an error when no value is entered for either of those fields. Following is the error message. I will paste the script below it as well. Any help would be appreciated. I have a similar problem with a few other scripts that are giving error with NULL when no value is entered. I really don't know how to fix this. Please help!
Thank you so much!
Error:
2020-04-15 12:53:44,914 ERROR [runner.ScriptFieldPreviewRunner]: ************************************************************************************* 2020-04-15 12:53:44,916 ERROR [runner.ScriptFieldPreviewRunner]: Script field preview failed for field that has not yet been created java.lang.NumberFormatException: For input string: "null" at java_lang_Float$parseFloat.call(Unknown Source) at Script324.run(Script324.groovy:11)
Script:
import com.atlassian.jira.component.ComponentAccessor;
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;
import java.text.SimpleDateFormat;
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def storyPointsField = customFieldManager.getCustomFieldObject((Long)10018)
def storyPoints = Float.parseFloat(issue.getCustomFieldValue(storyPointsField).toString())
def priorityField = customFieldManager.getCustomFieldObject((Long)14103)
def priority = issue.getCustomFieldValue(priorityField).toString()
def priorityNumber = Integer.parseInt(priority.split("-")[0].trim())
def effort = Double.parseDouble(((6-priorityNumber)/storyPoints).toString())
return effort