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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

152 views 1 17
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