I have a custom scripted field named "Epic Σ Original Estimate (Hours)" which holds a numeric value.
I have another custom scripted field named "Feature Σ Original Estimate (Hours)" which I need to sum up the total held in "Epic Σ Original Estimate (Hours)" for any related Epics.
In my groovy script I'm making use of getCustomFieldValue but even though I can see I have a value in "Epic Σ Original Estimate (Hours)" it's not being pulled through.
Am I making a beginners error in trying to reference the value returned by a custom scripted field from another custom scripted field?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkType
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.CustomFieldManager
def cfManager = ComponentAccessor.getCustomFieldManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def customField = customFieldManager.getCustomFieldObjectByName("Epic Σ Original Estimate (Hours)");
long originalEstimateTotal = 0
// Perform only for Epics
if (issue.getIssueType().name == "Epic") {
IssueLinkTypeManager issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)
IssueLinkManager issueLinkManager = ComponentAccessor.issueLinkManager
// Get all the top level issues in the Epic.
Collection<IssueLinkType> epicToStoryLinkTypes = issueLinkTypeManager.getIssueLinkTypesByName('Roadmap Item Relationship')
if (epicToStoryLinkTypes) {
def linkedStories = issueLinkManager.getOutwardLinks(issue.id).findAll{it.linkTypeId == epicToStoryLinkTypes[0].id}*.destinationObject
if (linkedStories.size() > 0) {
// Process each issue linked to the Epic
for (int index = 0; index < linkedStories.size(); index++) {
Issue currentIssue = linkedStories[index]
if (currentIssue) {
log.warn("value=" + currentIssue.getCustomFieldValue(customField))
log.warn("key=" + currentIssue.getKey() )
originalEstimateTotal = originalEstimateTotal += currentIssue.getCustomFieldValue(customField) ?: 0
}
}
}
}
}
return originalEstimateTotal
I am not Groovy savvy, but regarding this line:
originalEstimateTotal = originalEstimateTotal += currentIssue.getCustomFieldValue(customField) ?: 0
Should this instead be:
originalEstimateTotal += currentIssue.getCustomFieldValue(customField) ?: 0
Just wondering if rather than using the script, have you considered performing this addition with an automation rule for the project when the field changes? Please see here for more information:
Best regards,
Bill
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.