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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

Hello,

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,
Jay

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('com.microsoft.sqlserver.jdbc.SQLServerDriver').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 ->
sb.append("${r.hours}")
}
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 {
sql.close()
}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

689 views 17 19
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you