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

Get "Time Spent" from External tool and populate "Time Spent" Jira field

Jay Salvay August 22, 2018


I want to know how to proceed to connect an external tool and Jira through Script Runner to get a "Time Spent" value from an external billing tool.

The external billing tool already have each billing task with some fields, 2 of the very important to me to use. One of them is the "Time Spent" for that specific billing task and then, there is a field named "Jira ID" which have the JIRA ID for the specific task worked in Jira.

I want to:
1) Be able to use SR to query the BD (SQL server) on this external billing tool and get these 2 fields ("JIRA ID" and "Time Spent").

2) Then, use "JIRA ID" field to look for this specific "Jira ID" in Jira instance and based on this, to populate the "Time Spent" Jira field with the "Time Spent" field from the external billing tool.

Is this possible, can you help me to do this?

Thanks in advance,

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Jay Salvay September 11, 2018

Hi all, I wasable only to get the time spent, but not able to update it yet. Here is my script until now.


import groovy.sql.Sql
import java.sql.Driver
import com.atlassian.jira.component.ComponentAccessor

def driver = Class.forName('').newInstance() as Driver
def props = new Properties()
props.setProperty("user", "[DB USER HERE]")
props.setProperty("password", "[DB PASSWORD HERE]")
def conn = driver.connect("jdbc:sqlserver://[SERVER IP]:[SERVER PORT]", props)
def sql = new Sql(conn)
def key = issue.getKey()

def sqlStmt = "SELECT isnull(sum(hours),0) hours FROM account.dbo.invoice JOIN account.dbo.projects ON invoice.project = projects.Project WHERE cast(isnull(projects.JIRAID,'') as varchar) = '" + key + "';"
String test = ' '
Double timeWorked = 0
double progress = 0
double timeEstimated = issue.getOriginalEstimate()
try {
StringBuilder sb = new StringBuilder()
sql.eachRow(sqlStmt) { r ->
test = sb.toString()
timeWorked = Double.parseDouble(test)
if (timeWorked == null) timeWorked = 0
if (timeEstimated == null) timeEstimated = 0

def subTaskManager = ComponentAccessor.getSubTaskManager();
Collection subTasks = issue.getSubTaskObjects()

if (subTaskManager.subTasksEnabled && !subTasks.empty) {
subTasks.each {
if (it.getOriginalEstimate() != null) timeEstimated += it.getOriginalEstimate()
if ((timeEstimated != 0 && timeWorked != 0) || (timeEstimated == 0 && timeWorked != 0)) {
progress = ((timeWorked * 60 * 60) / timeEstimated) * 100
} else {
progress = 0
//return timeEstimated
//return (timeWorked * 60 * 60)
return progress.round(5)

finally {

AUG Leaders

Atlassian Community Events