Multiple Errors in Logs after JIRA upgrade: Calculated Field

The following calculated field script was written by another user and am not familiar with this scripting. I recently updated our test JIRA instance from 6.3 to 7.1 and I am trying to resolve a single error that is repeated over and over in my logs (over 500 times just today) but I don't understand what the error is explaining. The error is not thrown in my production instance which has not yet been upgraded.  Here is the script: 

<!-- @@Formula:
 
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.link.IssueLink;
 
double sumCustomFieldValues(linkedIssues, customFieldId, linkTypeId) {
 double sum = 0;
 
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObject(customFieldId);
 
 for(int i = 0; i < linkedIssues.size(); i++){
 
    IssueLink link =  linkedIssues.get(i);
 
    if(link.getIssueLinkType().getId() == linkTypeId){
       Double customFieldValue = link.getDestinationObject().getCustomFieldValue(customField);
       sum += (customFieldValue == null) ? 0 : customFieldValue;
    }
 
 }
 
 
 return sum;
}
 
sumCustomFieldValues(issue.get("issuelinks"), 12817, 10001);
 
-->

Here is the error: 

.../rest/api/2/search [c.i.jmcf.fields.CalculatedNumberField]
CalculatedNumberField: error evaluating formula of field "SW Developer
Estimate" of issue ASPM-11568: 


Sourced file:
inline evaluation of: ``     import
com.atlassian.jira.ComponentManager; 
import com.atlassian.jira.issu . . . '' : Typed variable declaration :
Error in method invocation: Method getCustomFieldManager() not found in
class'com.atlassian.jira.ComponentManager' : at Line: 11 : in file: inline
evaluation of: ``     import
com.atlassian.jira.ComponentManager; 
import com.atlassian.jira.issu . . . '' : .getCustomFieldManager ( ) 

Called from method: sumCustomFieldValues : at Line: 29 : in file: inline evaluation
of: ``     import
com.atlassian.jira.ComponentManager; 
import com.atlassian.jira.issu . . . '' : sumCustomFieldValues ( issue
.get ( "issuelinks" ) , 12817 , 10001 )

I believe this is an Innovalog plugin error but am used to seeing errors written as com.innovalog... not as c.i.jmcf...

Can anyone help me figure out what is wrong with the script?

1 answer

1 accepted

Accepted Answer
1 vote

Hi,

this happens because JIRA 7 deprecated a lot of its internal APIs, and com.atlassian.jira.ComponentManager is one of them, replaced with ComponentAccessor.

Here's an untested version of your script with a tentative fix:

<!-- @@Formula:
  
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.link.IssueLink;
  
double sumCustomFieldValues(linkedIssues, customFieldId, linkTypeId) {
 double sum = 0;
  
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField customField = customFieldManager.getCustomFieldObject(customFieldId);
  
 for(int i = 0; i < linkedIssues.size(); i++){
  
    IssueLink link =  linkedIssues.get(i);
  
    if(link.getIssueLinkType().getId() == linkTypeId){
       Double customFieldValue = link.getDestinationObject().getCustomFieldValue(customField);
       sum += (customFieldValue == null) ? 0 : customFieldValue;
    }
  
 }
  
  
 return sum;
}
  
sumCustomFieldValues(issue.get("issuelinks"), 12817, 10001);
  
-->

 

 

Hi David,

This worked perfectly and no more errors show in my logs. 

Thanks so much!

Avril 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

21,651 views 2 7
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