Cannot get worklog attributes from worklogs



I've been trying to get worklog attributes from worklogs that are being entered. I want to find out if the worklog has the attribute _overtime_ and if so which value it has. I have a groovy script that is being called when the event worklogadd is executed.

The worklog element simply does not contain any attributes that have been created in Tempo so I have tried several things. I've tried to contact the Tempo plugin by using Rest:

String JIRA_API_URL = "http://OUR_SERVER/rest/tempo-timesheets/3/worklogs/" +

HTTPBuilder jira = new HTTPBuilder(JIRA_API_URL)
jira.client.addRequestInterceptor(new HttpRequestInterceptor() {
void process(HttpRequest httpRequest, HttpContext httpContext) {
httpRequest.addHeader('Authorization', 'Basic ' + 'ProgramUser:admin'.bytes.encodeBase64().toString())

def tempoWorklog = jira.get(path: JIRA_API_URL )
log.warn("\nLogFlexTime worklogproperties issue " + tempoWorklog + "\n" +

This does give a result, but the object that is returned contains an empty workAttributeValues list. I have no idea why the workAttributeValues is empty. All the other values are there in the worklog object that is returned.


I've also tried the non rest way decribed here:


import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.tempoplugin.worklog.attribute.WorklogAttributeService
WorklogAttributeService worklogAttributeService
boolean isOvertime = worklogAttributeService.getWorklogAttributes(11014).containsKey("_Overtime_")
log.warn("\nLogFlexTime isOvertime " + isOvertime)


This fails with the following error:

LogFlexTime.groovy: 24: unable to resolve class com.tempoplugin.worklog.attribute.WorklogAttributeService
@ line 24, column 1.
import com.tempoplugin.worklog.attribute.WorklogAttributeService

1 error


So I'm a bit lost here. I really need to figure out if the time logged on an issue is overtime or not. Anybody got any tips on this one?

2 answers

What version of JIRA & Tempo are you using? We updated the docs for working with Tempo in 4.3.7 to work with Tempo 8; prior versions should work with Tempo 7.

Hi Jonny. We're using the latest versions of both:

Scriptrunner - 4.3.19

Tempo Timesheets - 8.2.5 


I see now that I have looked at the old documentation and that in the new documentation some of the imports have changed packaga path. Might be the problem. I'll check and get back to you.


Thanks so far Jonny.

So I've tried the new package paths and I'm now able to use WorkAttributeService and WorkAttributeValueService.


This is great I'm able to get worklog attribute Ids:


WorkAttribute attribute = workAttributeService.getWorkAttributeByKey("_Overtime_").returnedValue
WorkAttributeValue overtimeValue = workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(11049, attribute.getId()).returnedValue


The call to getWorkAttributeValueByWorklogAndWorkAttribute unfortunatley returns null.


Could it be that I need to index the issue before trying to get the attribute value for it?


To start from the beginning. The user records a worklog and there selects a dropdown item called Overtime. I then have a listener active for getting worklog added events. This is triggered and I then try to call the code above on the worklog item that comes in the event. Am I doing this too soon or something? 


I've tried to run the same code in the Scriptrunner console, but then by hardcoding a worklog id. It then works perfectly. It's only when I do this from the event that it resturns null

Do you have any idea Jonny?

I've found the reason for the problem.

Well at least the workaround. The original issue that the worklog attributes are not included in the event is still an issue, but the workaround to get them form the DB is now solved. The problem is that the events in JIRA isn't asynchronous. So the events (worklog created, worklog updated, worklog deleted) are all waiting for the script in the listener to run before they finish. So the worklog isn't actually stored in the DB before the scripts attached to the listeners are ran. No wonder the searches returned null ;)

So my way of solving this is to add a Thread in the script and look for the needed values in that thread instead. That way the values are stored while the script is running and I can fetch them from the DB.

Hey there,

Any chance you could share that Thread part?

Thread thread = new Thread() {
public void run() {

//Do what needs to be done in a separate thread here.

Thanks! Did you put all of your logic in that thread or just the retrieval of the worklogattribute value?


Would love to see your code. 

I put all the logic there or in methods that I call from the thread.

This is the code to get the attribute:

WorkAttributeValue workAttributeValue = null;
int i = 0; //stop after 1000 tries so that it doesn't go into an infinite loop
while (workAttributeValue == null && i < 100000) {
ServiceOutcome<WorkAttributeValue> serviceOutcome = workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(
issueEvent.getWorklog().getId(), workAttribute.getId());
workAttributeValue = serviceOutcome.getReturnedValue();
//log.warn("\nLogFlexTime workAttributeValue " + i + " " + workAttributeValue + " " + + " " + workAttribute.getId())


It's in a while as it can take some time for the original tread that stores the values in the DB  to finish. This new tread which retrieves the data again cannot do it too soon.

Thanks, been looking for this.

I wrote a listener that uses the worklog entries to update object attribute values in Insight (Asset management). This part was missing since I only want to do it on certain attribute values.

If you want, could you share the entire listener code to 

If you're interested, I could share my code of updating insight objects.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 13, 2019 in Jira

Make your Atlassian Cloud products more secure: our NEW admin security guide

Hey admins! I’m Dave, Principal Product Manager here at Atlassian working on our cloud platform and security products. Cloud security is a moving target. As you adopt more products, employees consta...

599 views 0 12
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you