Hi All,
My JIRA instance have issues linked to other issues with a specific link type, e.g (relates to) and specific issue type, e.g (bug) I'm trying to sum all the work logged in all bug issues with relates to link . Example. Ticket ABC-1 is linked to ABC-2(release), ABC-3(bug), ABC-4 (bug), ABC-5(bug) and BCD-1 (new) (in another project) i'm trying to sum total work log in all these tickets and store it in a scripted field eventually for this project. I found out that using groovy script is the best way to do it. I have done some research and I have written this code from script console to try out but i'm stuck. ABC-2 has work logged as null, but the rest of the issues has work logged. I cannot seem to continue checking the rest of the issues apart from the first one from the script and I'm stuck Here is the script. Please help
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.IssueManager def issueLinkManager = ComponentAccessor.getIssueLinkManager() def issueManager = ComponentAccessor.getIssueManager() MutableIssue issue = issueManager.getIssueObject("ABC-1") def totalTimeSpent = 0 issueLinkManager.getOutwardLinks(issue.id).each {issueLink -> def linkedIssue = issueLink.destinationObject if(issueLink.issueLinkType.name == "Relates" || linkedIssue.getIssueType() == "Bug"){ def linkedIssueTimeSpent = linkedIssue.timeSpent if(linkedIssueTimeSpent) { totalTimeSpent += linkedIssueTimeSpent } } } if(totalTimeSpent > 0) { totalTimeSpent = totalTimeSpent / 60.0d / 60.0d / 8.0d return (double)totalTimeSpent } else{ null }
This is very similar to this example: https://scriptrunner.adaptavist.com/latest/jira/recipes/scriptfields/workRemainingInLinkedIssues.html - did you check that out?
Also it would help readability if the code was formatted properly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Relates is tricky because the destinationObject might be the current issue. Try adding the relates link the other way as well to see if that's the problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie, You are right. Relates is a bit tricky with destinationObject. It worked for me. Sorry for saying this a bit late. Thanks for your help...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
Here is my original code
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.IssueManager def issueLinkManager = ComponentAccessor.getIssueLinkManager() def issueManager = ComponentAccessor.getIssueManager() MutableIssue issue = issueManager.getIssueObject("ABC-1") def totalTimeSpent = 0 issueLinkManager.getOutwardLinks(issue.id).each { issueLink -> def linkedIssue = issueLink.destinationObject //if(linkedIssue.getIssueType() == "Bug"){ if (issueLink.issueLinkType.name == "Relates" || linkedIssue.getIssueType() == "Bug") { def linkedIssueTimeSpent = linkedIssue.timeSpent if (linkedIssueTimeSpent) { totalTimeSpent += linkedIssueTimeSpent } } } if (totalTimeSpent > 0) { totalTimeSpent += issue.timeSpent //totalTimeSpent = totalTimeSpent / 60.0d / 60.0d / 8.0d //Seconds to Hours return (double) totalTimeSpent } else { null }
I've seen that example and it didn't work for me... Please help to point where I missed out something.
it prints "null"... and there is no stack trace
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I fixed the formatting. Can you post a stack trace or something, or what the actual result is compared to the expected.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
linkedIssue.getIssueType() returns an issue type not a string. So you would want: linkedIssue.issueType.name == "Bug" there may be other problems too.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie, This is how it looks like. issueLinkManager.getOutwardLinks(issue.id).each {issueLink -> def linkedIssue = issueLink.destinationObject if(issueLink.issueLinkType.name == "Relates" || linkedIssue.issueType.name == "Bug"){ def linkedIssueTimeSpent = linkedIssue.timeSpent if(linkedIssueTimeSpent) { totalTimeSpent += linkedIssueTimeSpent } } } if(totalTimeSpent > 0) { totalTimeSpent += issue.timeSpent //totalTimeSpent = totalTimeSpent / 60.0d / 60.0d / 8.0d //Seconds to Hours return (double)totalTimeSpent } else{ null } It returns "null"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you attach a screenshot of the script field config, and one where you see the "null"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.