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

Scriptrunner scripted fields integration with Tempo fails

Patrick van der Rijst
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 15, 2018

Performing the same script via the Script Console works but via the Scripted Field it fails to retrieve Tempo data like worklog attributes. Are these maybe not saved yet? How to deal with this?

Listening for the event Work Logged on Issue

def attribute = workAttributeService.getWorkAttributeByKey("_Account_").returnedValue
return workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(latestWorkLog.id, attribute.id).returnedValue.value

"returnedValue" is empty during a scripted field execution, it works fine via the Script Console.

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Patrick van der Rijst
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2018

Skipping some code but this should help. Like mentioned, retrieving this via the script console, by taking one of the last worklogs, works but via this listener it's null

 

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


def issue = event.issue
def workLogs = worklogManager.getByIssue(issue)
def latestWorkLog = workLogs.sort {it.id}.last()
def timeSpent = latestWorkLog.getTimeSpent()

def attribute = workAttributeService.getWorkAttributeByKey("_Account_").returnedValue // Account
log.error attribute
def accountValue = workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(latestWorkLog.id, attribute.id)
log.error("Ret value ==== " + accountValue.returnedValue)

Horst Krause October 12, 2018

Hi. Did you ever solve this issue? I'm also trying to use a scripted field to get the Tempo Account Category as an issue value. Like you described in preview it works fine, but in JQL and filter gadgets the returned value is null.

Patrick van der Rijst
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 12, 2018

No.. Tempo fills the value after this event. Maybe they’ll add their own worklog event containing attributes but for now it looks not possible.

Sammo Gabay November 20, 2018

Hi @Patrick van der Rijst, I was able to make this work with a slight hack:

// Accessing the event is not thread-safe, so cache any
// important info locally before starting the thread.
def deleted = event instanceof WorklogDeletedEvent
def worklogId = event.worklog.id as long
// ...

// HACK Call the API asynchronously after a delay.
// This is to allow the main thread to continue and hopefully ensure that the Tempo work attributes
// are saved. There is a miniscule chance the event will be fired before the main thread completes.
Thread.start {
Thread.sleep(2000)
def worklog = ComponentAccessor.worklogManager.getById(id)
// do somethind
}

This spins off a new thread and has it sleep before executing code that needs to know the values of work attributes. The gamble is that it needs the work attributes to be saved before the timer expires, so there is a slight race condition. Also, it’s important to grab the worklog id into a local variable, and then instantiate a new WorkLog object to grab any work attributes you need. Accessing the worklog event which is tossed into the script listener is inherently not thread-safe, so your event might be pointing at something else by the code inside your new thread executes.

Patrick van der Rijst
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 22, 2018

Yeah it's tricky, I've also tried threadings and sometimes it worked, sometimes it didn't. Tempo has mentioned they're thinking of implementing their own work log event that does include worklog attributes..

0 votes
Anton Chemlev - Toolstrek -
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2018

Hi,

Could you please provide full source code for your listener?

You can perform following steps:

1) Check out this topic https://community.atlassian.com/t5/Jira-questions/How-to-get-value-of-Tempo-Worklog-Attribute/qaq-p/453503

2) Add log.info, log.error etc. to you code in order to get info from logs.

TAGS
AUG Leaders

Atlassian Community Events