It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

 

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
Community showcase
Published in Jira Software

How to create Jira issus from Excel file?

When to use CSV importer When managing your processes in Jira, there are many occasions where you need to create a lot of tasks. Creating them one by one will cost you a lot of time and effort and i...

1,880 views 10 19
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you