One of my JIRA admins created a scripted field that would take 3 number fields and add them together (see below). However, the fields that are being added are only present on one screen (which is the same screen that the scripted field resides on). However, I'm seeing a ton of errors in my logs that suggest that the scripted field is attempting to be evaluated on every issue that is opened up, even if the scripted field has not been added to any screens for that issue. The error looks like this:
2015-05-26 09:34:26,857 devstatus.applink:thread-2 ERROR JM28299 442x38x1 1slsrh3 10.151.2.9 /browse/PNTH-19283 [onresolve.scriptrunner.customfield.GroovyCustomField] Script field failed on issue: DM-534, field: Priority Value
java.lang.NullPointerException: Cannot invoke method getValue() on null object
at Script3.run(Script3.groovy:18)
I realize that the get Value on null object problem is something that needs to be fixed for the original script anyway (any assistance on that end would also be appreciated), but the main problem here is that it's attempting to run the script for all issues no matter what.... shouldn't it only be running on issues that have added that scripted field?
Here is the code for the scripted field (in its current state):
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;
// Creates Issue and Custom Field Manager objects
IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
// Capture custom fields
CustomField customField_bv = customFieldManager.getCustomFieldObject( 13459 );
CustomField customField_ri = customFieldManager.getCustomFieldObjectByName( "Risk Index" );
CustomField customField_loe = customFieldManager.getCustomFieldObjectByName( "Level of Effort" );
CustomField customField_pv = customFieldManager.getCustomFieldObjectByName( "Priority Value" );
// Capture drop down values of custom fields
def businessValue = issue.getCustomFieldValue( customField_bv ).getValue();
def riskIndex = issue.getCustomFieldValue( customField_ri ).getValue();
def levelOfEffort = issue.getCustomFieldValue( customField_loe ).getValue();
// Only sum custom field values if NONE are null
if (businessValue!= null && riskIndex != null & levelOfEffort != null)
{
// Translate drop down values to double values
// Business Value
double businessValue_v;
if (businessValue == "1 - Low") {businessValue_v = 1; }
else if (businessValue == "2 - Medium") {businessValue_v = 2; }
else if (businessValue == "3 - High") {businessValue_v = 3; }
else {businessValue_v = 1000; } // should signal warning that a select drop down value is not recognized
// Risk Index
double riskIndex_v;
if (riskIndex == "1 - User Interface") {riskIndex_v = 1; }
else if (riskIndex == "3 - Management/Reporting") {riskIndex_v = 3; }
else if (riskIndex == "6 - Process Improvement") {riskIndex_v = 6; }
else if (riskIndex == "9 - Control/Error Prevention") {riskIndex_v = 9; }
else {riskIndex_v = 5000; } // should signal warning that a select drop down value is not recognized
// Level of Effort
double levelOfEffort_v;
if (levelOfEffort == "3 - Low (< 4hrs)") {levelOfEffort_v = 3; }
else if (levelOfEffort == "2 - Medium (5 - 11hrs)") {levelOfEffort_v = 2; }
else if (levelOfEffort == "1 - High (> 12hrs)") {levelOfEffort_v = 1; }
else {levelOfEffort_v = 8000; } // should signal warning that a select drop down value is not recognized
// Return Summed Values
return priorityValue = businessValue_v + riskIndex_v + levelOfEffort_v;
}