Referencing the value of a custom scripted field in another custom scripted field

graemejohnson June 30, 2020

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

 

1 answer

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 17, 2020

Hi @graemejohnson 

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:

https://support.atlassian.com/jira-software-cloud/docs/automate-your-jira-cloud-processes-and-workflows/

 

Best regards,

Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events