Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate avg of linked issues in parent issue

Saranya
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 22, 2023

Hi,

I have to implement a scripted field in Parent issue that calculates the average progress of linked issues.

I am using Java server version 80.20.17.

My parent issue is a story and linked issues can be tasks, support or improvement.

Currently my code calculates the sum of the progress for linked issue tasks. but it only takes into account the incorporated linked issues and not all the linked issues.

Can someone please help me modify the below code to calculate the average instead of sum of  incorporate all linked issues and not only incorporated linked issues.

progress% is a custom number field. 

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.Issue

// The issue type for which we want the scripted field to be displayed

final issueTypeName = 'Story'

// The linked issues with that issue type will used

final linkedIssueType = 'Task'

// The values of that custom field - of type number - we want to sum up

final numberOfUsersFieldName = 'Progress%'

if (issue.issueType.name != issueTypeName) {

    return null

}

def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id).findAll { it.destinationObject.issueType.name == linkedIssueType }

if (!linkedIssues) {

    return null

}

def numberOfUsersField = ComponentAccessor.customFieldManager.getCustomFieldObjects(linkedIssues.first().destinationObject).findByName(numberOfUsersFieldName)

if (!numberOfUsersField) {

    log.debug "Custom field is not configured for that context"

    return null

}

linkedIssues*.destinationObject.sum() { Issue it -> it.getCustomFieldValue(numberOfUsersField) ?: 0 }
Thank you in advance for your support

0 answers

Suggest an answer

Log in or Sign up to answer