Scripted field is getting evaluated for all issues

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

This widget could not be displayed.

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

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.

This widget could not be displayed.

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

 

 

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....

This widget could not be displayed.

@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....

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

534 views 23 15
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you