Hello, Guys!
I want to create two custom fields:
For the above two purposes I use the following link:
However, the time is not calculated.
My link name is "Composition"(I've attached an image "Link type - composition") like in the example:
However, there is no calculated time(attached image of field "").
Could you clarify what I am doing wrong?
We want to buy ScriptRunner, but we would like to learn how to use it before we buy it.
Thanks in advance!
In addition, I've attached my code.
Link type is:
No calculated time in field "Sum logged time of linked issues":
My code is:
package com.onresolve.jira.groovy.test.scriptfields.scripts
import com.atlassian.jira.component.ComponentAccessor
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def totalRemaining = 0
issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Composition") {
def linkedIssue = issueLink.destinationObject
totalRemaining += linkedIssue.getEstimate() ?: 0
}
}
// add the remaining work for this issue if there are children, otherwise it's just the same as the remaining estimate,
// so we won't display it,
if (totalRemaining) {
totalRemaining += issue.getEstimate() ?: 0
}
return totalRemaining as Long ?: 0L
In case of somebody need to calculate the sum of estimated time of all linked issues to the task.
package com.onresolve.jira.groovy.test.scriptfields.scripts
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.WorklogManager
import com.atlassian.jira.bc.issue.worklog.TimeTrackingConfiguration
def worklogManager = ComponentAccessor.getComponent(WorklogManager)
def workLogs = worklogManager.getByIssue(issue)
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def totalLoggedWork = 0
//totalLoggedWork = totalLoggedWork + issue.getTimeSpent() ?:0
issueLinkManager.getOutwardLinks(issue.id).each { issueLink ->
if (issueLink.issueLinkType.name == "Solve") {
def linkedIssue = issueLink.destinationObject
log.debug(linkedIssue)
log.debug(issueLink.issueLinkType.name)
totalLoggedWork += linkedIssue.originalEstimate ?: 0
}
}
def timeLoggedWork = ""
if(totalLoggedWork) {
def hours = totalLoggedWork / 3600;
def minutes = (totalLoggedWork % 3600) / 60;
def seconds = totalLoggedWork % 60;
timeLoggedWork = "часов: ${hours}, минут: ${minutes}, сек: ${seconds}"
log.debug(timeLoggedWork)
}
return timeLoggedWork
The sum of logged time:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.WorklogManager
import com.atlassian.jira.bc.issue.worklog.TimeTrackingConfiguration
import org.apache.log4j.Logger
import org.apache.log4j.Level
def worklogManager = ComponentAccessor.getComponent(WorklogManager)
def workLogs = worklogManager.getByIssue(issue)
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def log = Logger.getLogger("com.acme.ListLinks")
log.setLevel(Level.DEBUG)
def totalEstimatedWork = 0
issueLinkManager.getOutwardLinks(issue.id).each { issueLink ->
if (issueLink.issueLinkType.name == "Solve") {
def linkedIssue = issueLink.destinationObject
def linkedIssueWorkLogs = worklogManager.getByIssue(linkedIssue);
linkedIssueWorkLogs.each { linkedIssueWorkLog ->
totalEstimatedWork += linkedIssueWorkLog.getTimeSpent() ?: 0;
}
}
}
def timeEstimatedWork = ""
if(totalEstimatedWork) {
def hours = totalEstimatedWork / 3600;
def minutes = (totalEstimatedWork % 3600) / 60;
def seconds = totalEstimatedWork % 60;
timeEstimatedWork = "часов: ${hours}, минут: ${minutes}, сек: ${seconds}"
log.debug(timeEstimatedWork)
}
return timeEstimatedWork
The above code snippets calculates time for linked issues that has link type "Solve". If you want to calculate for all types, then just delete the following condition:
if (issueLink.issueLinkType.name == "Solve") { }
I paste the code, If somebody need it.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.WorklogManager
import com.atlassian.jira.bc.issue.worklog.TimeTrackingConfiguration
import org.apache.log4j.Logger
import org.apache.log4j.Level
//def issue = ComponentAccessor.getIssueManager().getIssueObject("ELIS-104")
def worklogManager = ComponentAccessor.getComponent(WorklogManager)
def workLogs = worklogManager.getByIssue(issue)
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def log = Logger.getLogger("com.acme.ListLinks")
log.setLevel(Level.DEBUG)
def totalEstimatedWork = 0
issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Solve") {
def linkedIssue = issueLink.destinationObject
def linkedIssueWorkLogs = worklogManager.getByIssue(linkedIssue);
linkedIssueWorkLogs.each {linkedIssueWorkLog ->
totalEstimatedWork += linkedIssueWorkLog.getTimeSpent() ?: 0;
}
}
}
def timeEstimatedWork = ""
if(totalEstimatedWork){
def hours = totalEstimatedWork / 3600;
def minutes = (totalEstimatedWork % 3600) / 60;
def seconds = totalEstimatedWork % 60;
timeEstimatedWork = "hours: ${hours}, minutes: ${minutes}, seconds: ${seconds}"
log.debug(timeEstimatedWork)
}
return timeEstimatedWork
package com.onresolve.jira.groovy.test.scriptfields.scripts
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.WorklogManager
import com.atlassian.jira.bc.issue.worklog.TimeTrackingConfiguration
def worklogManager = ComponentAccessor.getComponent(WorklogManager)
def workLogs = worklogManager.getByIssue(issue)
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def totalLoggedWork = 0
//totalLoggedWork = totalLoggedWork + issue.getTimeSpent() ?:0
issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->
if (issueLink.issueLinkType.name == "Solve") {
def linkedIssue = issueLink.destinationObject
log.debug(linkedIssue)
log.debug(issueLink.issueLinkType.name)
totalLoggedWork += linkedIssue.originalEstimate ?: 0
}
}
def timeLoggedWork = ""
if(totalLoggedWork){
def hours = totalLoggedWork / 3600;
def minutes = (totalLoggedWork % 3600) / 60;
def seconds = totalLoggedWork % 60;
timeLoggedWork = "hours: ${hours}, minutes: ${minutes}, seconds: ${seconds}"
log.debug(timeLoggedWork)
}
return timeLoggedWork
If you want to find a sum to all issues, then just remove the following condition and its brackets:
if (issueLink.issueLinkType.name == "Solve") { }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There's some things in your script that are a bit suspect, but they should all be picked up by the basic script editor built into ScriptRunner.
Could you go back to your script for the scripted field and look at the editor. Are there any red crosses next to any lines?
Then look below it, for a box labelled "preview issue" - put your master issue in there and click the preview button. You should see the calculated value appear, but there is also a "logs" tab there, and that's worth a look.
You can also embed log.debug ("something") lines into the script here to find out what it is doing and getting back from the issues. Inside the "issueLink ->" loop, I would try "log.debug(issueLink.issueLinkType.name + "//" + issueLink.getDestinationIssue.getKey() )" for example, to see what links it is reading and what the types are. Then another one inside the "if" to see if it gets there. And so-on
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nic, thanks for your reply. However, I've not found where Script Editor is located.
Do you mean Intellij IDEA by Script Editor?
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.