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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online 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.