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; }
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.