Forums

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

How to show average of the number field from the sub-task and to show on the parent task?

Teja
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.
June 16, 2020

Hello World,

Wanted to show the percentage complete on the parent task from the sub-task fields,

Just example:

Parent-Task Completed (Number field) on the Parent task.

Sub-Task Completed (Number field) on the Sub task.

Average of the "Sub-Task Completed" to show on the "Parent-Task Completed".

I have tried scripted number field it work perfectly fine. But I could not get the scripted field to show on Dataplane report, for the reason I have created Number field instead to show on report. 

Any script listeners?

2 answers

0 votes
Ali Türkkan August 18, 2021

Hi,

You can do this with the Field Teller Plugin available on the marketplace. The plugin's capabilities are to display the field on an Issue on another specified Issue.

You can Download it here: https://marketplace.atlassian.com/apps/1224310/field-teller?hosting=server&tab=overview

0 votes
Teja
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.
June 23, 2020

This code seems to be working


def issue = event.issue as Issue

//Subtask change event

def change = event?.getChangeLog()?.getRelated("ChildChangeItem").find {it.field == "Sub-Task Percentage Complete"}
if (! change) {
// there was no update do nothing!
return
}

if (! issue.isSubTask())
return

double total
double totalSum
double parentsum
def subTaskSum = 0

issue.getParentObject().subTaskObjects?.each {subtask ->
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10009")
def cfValue = subtask.getCustomFieldValue(cf)
if (cfValue != null) {
totalSum += subtask.getCustomFieldValue(cf) as double
}
subTaskSum += 1
}
total +=totalSum as double
parentsum = total / subTaskSum as double
log.warn "total :" +total
log.warn "average :" +parentsum

//Get the parent object
MutableIssue parentIssue = issue.getParentObject();
def parent = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_14315")
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def changeHolder = new DefaultIssueChangeHolder()
parent.updateValue(null, parentIssue, new ModifiedValue(parentIssue.getCustomFieldValue(parent), parentsum),changeHolder)

 Regards

Tejas

Suggest an answer

Log in or Sign up to answer