Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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 Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

224 views 2 1
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