You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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
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()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.