JIRA tally all logged work from linked issues and sub tasks to single issue

jeff singler July 16, 2020

I have tried several different groovy script methods form various examples as I am not a coder, but have come close but no real success. I have thrown my hands up and am wondering if some smart person out there knows how to do this.

I simply need to show all total work logged for a specific link type of parent issues and their sub tasks to a single issue as a grand total. See diagram.Untitled Diagram.png

1 answer

1 accepted

1 vote
Answer accepted
Radek Dostál
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

When you say groovy script methods it's a bit ambiguous what you are trying to do exactly, but, if I understood this right I've set it up with a Script Field which fingers crossed gets you closer.

 

This seems to work in my tests and I'm getting expected values on the Asset Record in your pic:

// Template: Duration (either of the 2)

import
com.atlassian.jira.component.ComponentAccessor

def issueLinkmanager = ComponentAccessor.getIssueLinkManager()
def subtaskManager = ComponentAccessor.getSubTaskManager()
def workLogManager = ComponentAccessor.getWorklogManager()

def linkName = "Work"


def linkCollection = issueLinkmanager.getLinkCollectionOverrideSecurity(issue)
def linkedIssues = linkCollection?.getOutwardIssues(linkName) //Inward or Outward? Verify and change if needed.

if (!linkedIssues) {
// no linked issues
return null
}

def totalTimeSpentFromWorkLinkedIssuesAndTheirSubtasks = []

for (def linkedIssue:linkedIssues) {
def worklogList = workLogManager.getByIssue(linkedIssue)
for (def worklog:worklogList) {
def timeSpent = worklog.getTimeSpent()
totalTimeSpentFromWorkLinkedIssuesAndTheirSubtasks.add(timeSpent)
}

def subTasks = subtaskManager.getSubTaskObjects(linkedIssue)
for (def subTask:subTasks) {
def worklogListSubTask = workLogManager.getByIssue(subTask)
for (def worklogSubTask:worklogListSubTask) {
def timeSpent = worklogSubTask.getTimeSpent()
totalTimeSpentFromWorkLinkedIssuesAndTheirSubtasks.add(timeSpent)
}
}
}

return totalTimeSpentFromWorkLinkedIssuesAndTheirSubtasks?.sum()

 

jeff singler July 17, 2020

You're a genius, that worked like a charm.  No more head pounding.  Thank you so much, here is a virtual beer on me!

jeff singler July 17, 2020

Also yes, we are using scriptrunner using a scripted field.

Suggest an answer

Log in or Sign up to answer