Forums

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

sum of field value of subtasks for parent

Marzi Goodarzian
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.
January 22, 2023

Hello

I wrote a script field that show "time spent" for every subtask, now I want collect (sum) this field from all of subtasks for a parent shown  in parent field:

1)return time spent based on Hourse for subtask:

****

import com.atlassian.jira.issue.changehistory.ChangeHistoryManager;
import com.atlassian.jira.issue.changehistory.ChangeHistory;
import com.atlassian.jira.model.ChangeItem;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.issue.changehistory.ChangeHistoryItem;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.*
import com.atlassian.jira.issue.worklog.Worklog
ChangeHistoryManager changeHistoryManager =ComponentAccessor.getChangeHistoryManager();
List <ChangeItemBean> changeItemBeans= changeHistoryManager.getChangeItemsForField(issue, "timespent");
  return ((changeItemBeans.last().getToString() as Long)/3600).toDouble()
 

 

2)sum of subtasks field(LogSpent) for parent:

*******

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
//14521=logSpent Field ID
CustomField LogSpent = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(14521);
double totalSum = 0;

issue.getSubTaskObjects().each {subtask->
    if(subtask.getCustomFieldValue(LogSpent) != null)
       totalSum +=  subtask.getCustomFieldValue(LogSpent);
     
}
return totalSum
I also used this:
totalSum +=  Double.parseDouble(subtask.getCustomFieldValue(LogSpent));
but in second script show error and can't sum these values, How can fix it?
Thanks for help

0 answers

Suggest an answer

Log in or Sign up to answer