I have a calculated numeric script field intended to return an importance value based on various custom fields. When testing with any individual issue, this works; the number is visible on the issue and updated as I change elements and save.
However, when I add this field as a column to a search, the column is blank and ScriptRunner history tells me "All of the last 15 executions have failed." It does appear that sorting works despite this.
I suspect the failure has something to do with how the code is determining the issue to execute against, but I'm not well-versed in this language and don't fully understand why or how to fix it. Can anyone assist?
The Searcher is set to Number Range Searcher and JIRA has been re-indexed since that change.
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.MutableIssue
double weighted_rank = 0
double weight_percent = 0
double score = 0
double force_rank_value = 0
def issue = issue as MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
// 20% - JIRA Priority
score = 0
weight_percent = 22.2
def jira_priority = Integer.parseInt(issue.priorityObject.id)
if (jira_priority == 5) {score = 1}
if (jira_priority == 4) {score = 3}
if (jira_priority == 3) {score = 5}
if (jira_priority == 2) {score = 8}
if (jira_priority == 1) {score = 10}
weighted_rank = weighted_rank + score*weight_percent
// 5% - Future Clients Impacted
customfieldname = "Future Clients Impacted"
weight_percent = 6.7
score = 0
def future_clients = getCustomFieldValue(customfieldname)
if (future_clients != null) {
if (future_clients.getValue()== null) {score = 0}
if (future_clients.getValue()=="None") {score = 0}
if (future_clients.getValue()=="One") {score = 1}
if (future_clients.getValue()=="Few") {score = 2}
if (future_clients.getValue()=="Many") {score = 5}
if (future_clients.getValue()=="All") {score = 10}
weighted_rank = weighted_rank + score*weight_percent
}
// 15% - Current Clients Impacted
customfieldname = "Clients"
weight_percent = 13.3
score = 0
def client_list = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Clients" }
def client_list_values = issue.getCustomFieldValue(client_list)
if (client_list_values != null) {
def numberOfSelections = client_list_values.size()
if (numberOfSelections == 0) {score = 0}
if (numberOfSelections == 1) {score = 1}
if (numberOfSelections == 2) {score = 3}
if (numberOfSelections > 2 && numberOfSelections < 5) {score = 6}
if (numberOfSelections > 4) {score = 10}
weighted_rank = weighted_rank + score*weight_percent
}
weighted_rank = weighted_rank / 10
// Force Rank
customfieldname = "Force Importance"
score = 0
def force_importance = getCustomFieldValue(customfieldname)
if (force_importance != null) {
if (force_importance.intValue() != null) {weighted_rank = force_importance.intValue()}
}
return weighted_rank