Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Groovy Scripted fields - Linked issues returns null.

Gantner November 27, 2015

Hi,

I'm creating a scripted field in JIRA which will calculate the total of the time spent of the linked issues (LinkType = 'Test') 

However i'm new in JIRA and scripted fields and I'm struggling with some issues. 

I've written the following script but when I call the line below, i always get null back. Also when I change this to GetSummary or something else. I always get null  

  def timespent = linkedIssue.getTimeSpent() 

 

import com.atlassian.jira.ComponentManager

def componentManager = ComponentManager.getInstance()
def issueLinkManager = componentManager.getIssueLinkManager()

def totalSpent = 0D
issueLinkManager.getInwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Test") {
def linkedIssue = issueLink.getDestinationObject()
def timespent = linkedIssue.getTimeSpent()
if (timespent){
totalSpent = totalSpent + timespent 
}

}
}
return totalSpent ? componentManager.getJiraDurationUtils().getFormattedDuration(totalSpent ) : null

Am I doing something wrong ? 

Kind regards 

  Rob 

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Thanos Batagiannis _Adaptavist_
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.
November 27, 2015

Hi Rob,

issueLinkManager.getInwardLinks(issue.id)

give to you links TO your issue (let's call it 'first') and the line 

def linkedIssue = issueLink.getDestinationObject()

will give you for all the incoming issues the destination, which is always the 'first' issue. If I understand well you want the total time spent for the linked issues, therefore you should get the source issues

def linkedIssue = issueLink.getSourceObject()

PS. It is also better to use ComponentAccessor to get the issueLinkManager and the jiraDurationUtils (ComponentManager is getting deprecated) 

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def jiraUtils = ComponentAccessor.getJiraDurationUtils()

Please let me know if this helps

0 votes
Daniil Lyovkin November 27, 2015

Try using 

issueLinkManager.getOutwardLinks(issue.id)

instead 

issueLinkManager.getInwardLinks(issue.id)

maybe you need links from an issue, but not links to an issue.

TAGS
AUG Leaders

Atlassian Community Events