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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

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


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

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 {

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events