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'm trying to fetch the value of a work attribute (In Tempo; a 'Select list' called 'Type') on a work log using a custom listener script.
I can successfully fetch the value of the work attribute when executing the script in Scriptrunner's Script Console using the following script;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.WorklogManager
// Tempo>>>
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.tempoplugin.core.workattribute.api.WorkAttributeService
import com.tempoplugin.core.workattribute.api.WorkAttributeValueService
@WithPlugin("is.origo.jira.tempo-plugin")
@PluginModule
WorkAttributeService workAttributeService
@PluginModule
WorkAttributeValueService workAttributeValueService
// <<<Tempo
// Dev-mode>>>
import com.atlassian.jira.issue.managers.DefaultIssueManager
def issueManager = ComponentAccessor.getComponent(DefaultIssueManager)
def issue = issueManager.getIssueObject("TEST-1") as Issue
log.warn(issue)
// <<<Dev-mode
/* Define current issue on which the event is triggered
def issue = event.issue
log.warn(issue)
*/
// Define Manager
def worklogManager = ComponentAccessor.getComponent(WorklogManager)
// Get latest work log id
def logId = worklogManager.getByIssue(issue).last()
log.warn(logId)
log.warn(logId.id)
// Define Work Attribute
def attType = workAttributeService.getWorkAttributeByKey("_Type_").returnedValue
log.warn(attType)
log.warn(attType.id)
// Get Work Attribute Value
def attributeValue = workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(logId.id, attType.id).returnedValue
log.warn(attributeValue)
log.warn(attributeValue.value)
Above script returns the following;
2018-09-09 05:09:06,462 WARN [runner.ScriptRunnerImpl]: TEST-1
2018-09-09 05:09:06,462 WARN [runner.ScriptRunnerImpl]: com.atlassian.jira.issue.worklog.WorklogImpl2@7e33b887
2018-09-09 05:09:06,463 WARN [runner.ScriptRunnerImpl]: 10657
2018-09-09 05:09:06,463 WARN [runner.ScriptRunnerImpl]: com.tempoplugin.core.workattribute.api.WorkAttribute@5d3c9709
2018-09-09 05:09:06,463 WARN [runner.ScriptRunnerImpl]: 5
2018-09-09 05:09:06,465 WARN [runner.ScriptRunnerImpl]: com.tempoplugin.core.workattribute.api.WorkAttributeValue@598fce84
2018-09-09 05:09:06,465 WARN [runner.ScriptRunnerImpl]: Testing
"Testing" is the name of the value of the attribute called 'Type' in this particular worklog.
This is what I want so it is working as expected in the script console.
However, when using this script (Slightly modified) as a custom listener, listening on the event "Work Logged On Issue", the 'attributeValue' returns nothing.
The only difference is how I define 'issue'. Here's that script;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.WorklogManager
//###Tempo>>>
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.tempoplugin.core.workattribute.api.WorkAttributeService
import com.tempoplugin.core.workattribute.api.WorkAttributeValueService
@WithPlugin("is.origo.jira.tempo-plugin")
@PluginModule
WorkAttributeService workAttributeService
@PluginModule
WorkAttributeValueService workAttributeValueService
//<<<Tempo###
/*
//###Dev-mode>>>
import com.atlassian.jira.issue.managers.DefaultIssueManager
def issueManager = ComponentAccessor.getComponent(DefaultIssueManager)
def issue = issueManager.getIssueObject("TEST-1") as Issue
log.warn(issue)
//<<<Dev-mode###
*/
// Define current issue on which the event is triggered
def issue = event.issue
log.warn(issue)
// Define Manager
def worklogManager = ComponentAccessor.getComponent(WorklogManager)
// Get latest work log id
def logId = worklogManager.getByIssue(issue).last()
log.warn(logId)
log.warn(logId.id)
// Define Work Attribute
def attType = workAttributeService.getWorkAttributeByKey("_Type_").returnedValue
log.warn(attType)
log.warn(attType.id)
// Get Work Attribute Value
def attributeValue = workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(logId.id, attType.id).returnedValue
log.warn(attributeValue)
log.warn(attributeValue.value)
Above script returns the following;
2018-09-09 05:24:45,306 WARN [runner.ScriptRunnerImpl]: TEST-1
2018-09-09 05:24:45,309 WARN [runner.ScriptRunnerImpl]: com.atlassian.jira.issue.worklog.WorklogImpl2@44dbc585
2018-09-09 05:24:45,309 WARN [runner.ScriptRunnerImpl]: 10657
2018-09-09 05:24:45,309 WARN [runner.ScriptRunnerImpl]: com.tempoplugin.core.workattribute.api.WorkAttribute@5d3c9709
2018-09-09 05:24:45,309 WARN [runner.ScriptRunnerImpl]: 5
2018-09-09 05:24:45,310 WARN [runner.ScriptRunnerImpl]:
As you can see, the 'attributeValue' doesn't return anything here.
The strange thing is that it actually works sometimes if I add the "Issue Worklog Deleted" event and delete a worklog (At least one worklog needs to be left).
I'm using the following versions;
Any thoughts on why this only seem to work in the Script Console and not as a listener?
Thanks in advance!
Best regards,
Markus Fredén
Hi,
I personnaly fetched it from AO_013613_WA_VALUE table in the database,
import groovy.sql.Sql
import java.sql.Driver
def driver = Class.forName('com.mysql.jdbc.Driver').newInstance() as Driver
def props = new Properties()
props.setProperty("user", "username")
props.setProperty("password", "password")
String querydb = "SELECT Value,Worklog_ID FROM jiradb.AO_013613_WA_VALUE where value = '_Type_'"
def conn = driver.connect("jdbc:mysql://localhost:3306/jiradb", props)
def sql = new Sql(conn)
sql.eachRow(querydb) {
astreinte.put(it['Worklog_ID'],it['Value'])
}
regards.
Hi Florent,
Thanks for this, much appreciated.
I will most definitely use this if I dont find the way to do it without calling the db.
I will wait with accepting this as the answer until I have looked into it some more.
Best regards,
Markus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you should avoid executing direct database queries. The crux of the problem is that Tempo does not save all the work attributes until after your listener fires. However, I was able to get it to work using the Java API in the listener by spinning off a different thread that sleeps for a small time before trying to access the work attributes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.