Scripted field is getting evaluated for all issues

Jordan Packer May 27, 2015

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;
}

3 answers

1 accepted

2 votes
Answer accepted
Michael Johnson September 8, 2015

I believe this will be because your scripted field is still in the context of the project even if it is not displayed. Even if you never put a custom field on a screen you can still read its value or set it to something else.

You need to create a context in the "Custom Fields" admin area that confines the new field to only be relevant to the right project and the relevant issue types then it will stop evaluating for every issue in your instance.

 

MJ

Jordan Packer September 8, 2015

Thank you, Michael, for your answer. This certainly makes the most sense out of everything I've read, and I will go and give it a try.

0 votes
Jordan Packer July 8, 2015

@Jamie Echlin [Adaptavist] Any ideas? I really need to figure out why these scripts get evaluated any time you look at any issue... even if that scripted field does not exist on that issue/screen....

Ajinkya Paradkar August 5, 2020

@Jordan Packer  We are facing a similar error while Re-Indexing for some scripted fields.

The fields are not being used in any of the screens.

I came across a solution as :

The fix is to go to Admin -> Issues -> Custom Fields > choose your field (Edit) , and the choose "None" for the searcher template.

 

Can you suggest if this would be feasible to try ?

 

Thanks

Ajinkya

0 votes
Chander Inguva
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 27, 2015

What does it do if we add a condition to filter it by current project and current issue type.

Like

if (project == projectA) and (issuetype==Bug)
{
 execute bla bla bla
}

 

Let me know if this resolves your issue.

 

Regards

Chander Inguva

 

 

Jordan Packer May 27, 2015

I have a workaround to make it stop producing all of the errors (I now do a null value check on the three custom fields), but I'd still like to know what the script is running on all issues even though the scripted field hasn't been added to those projects....

Suggest an answer

Log in or Sign up to answer