How to get value of Tempo Worklog Attribute

CST JIRA Confluence Admin July 21, 2016

Hi all,

Is it possible to get the value of Tempo Worklog Attribute. We have 2 fields with the same name: 1 is scripted field and 1 field is work log attribute. We want to write a script to catch the value of Worklog Attribute and update it on Scripted Field because cannot export the value of Worklog Attribute to excel using Tempo.

4 answers

0 votes
Jonny Carter
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.
July 21, 2016

The missing bit from CST's earlier example is that we now need a WorkAttributeValueService as well. Fortunately, the handy-dandy PluginModule annotation can fetch that for us.

This is an example of a Scripted Field that gets all worklogs of a particular attribute type (Overtime), and sums them. You can extrapolate how to get multiple worklog attributes and their values.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.Worklog
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 worklogManager = ComponentAccessor.getWorklogManager()
def worklogs = worklogManager.getByIssue(issue)
def overtimeLogs = worklogs.findAll { worklog ->
    def attribute = workAttributeService.getWorkAttributeByKey("_Overtime_").returnedValue
workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(worklog.id, attribute.id).returnedValue
}

overtimeLogs.sum { Worklog worklog ->
    worklog.timeSpent
} as Long
CST JIRA Confluence Admin July 21, 2016

Thank Jonny. I've tried it and I think it is not the solution in my case. Here is the part of code that I use to get attribute key "_JobType_" based on your script.

 

def overtimeLogs = worklogs.findAll { worklog ->
    def attribute = workAttributeService.getWorkAttributeByKey("_JobType_").returnedValue
workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(worklog.id, attribute.id).returnedValue
}
I've tried to return overtimeLogs to see to return value but the result are below:
com.atlassian.jira.issue.worklog.WorklogImpl2@5a24404b, com.atlassian.jira.issue.worklog.WorklogImpl2@4ffbd790, com.atlassian.jira.issue.worklog.WorklogImpl2@3f89babe, com.atlassian.jira.issue.worklog.WorklogImpl2@7cfe4a88

The return value equal to the number of issue that have JobType attribute but how can I get the key value of dynamic dropdown box from Tempo. 
Jonny Carter
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.
July 25, 2016

Notice the last three lines of the script? That's the return value I used that sums up the timeSpent attribute of each worklog object. You'll need that or something like it to get the timespent as a number, instead of returning the WorklogImpl object itself.

Jens Helmstedt August 17, 2016

I tried to adopt this to check whether there is time spent on an issue but it didn't work.

I replaced "_Overtime_" with "timespent" and checked timeLogs == 0.

What did I wrong?

Jonny Carter
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.
August 17, 2016

If all that you want to know is whether any time has been spent on an issue, then you shouldn't need the Tempo classes at all. In fact, you may not even need the WorkLogManager. The getTimeSpent() method on the JIRA Issue object should suffice.

0 votes
CST JIRA Confluence Admin July 21, 2016

Hi Susanne and Mark,

Thank you for your quick answer. I've looked into it but It only allow you to get worklog info in JIRA for example: timespent, author, worklogid ... not worklog attribute on Tempo. Does Tempo have class available like this to get the value using Scripted Field.

ServiceOutcome<WorkAttribute> createWorkAttribute(WorkAttribute workAttribute);
 
ServiceOutcome<WorkAttribute> updateWorkAttribute(WorkAttribute workAttribute);
 
ServiceOutcome<Boolean> deleteWorkAttribute(int id);
 
ServiceOutcome<Collection<WorkAttribute>> getWorkAttributes();
 
ServiceOutcome<WorkAttribute> getWorkAttributeById(int id);
 
ServiceOutcome<WorkAttribute> getWorkAttributeByKey(String key);
 
ServiceOutcome<Collection<WorkAttribute>> getWorkAttributesByType(WorkAttributeType.Type type);
 
ServiceOutcome<Collection<WorkAttributeType>> getWorkAttributeTypes();
Can someone help me how to connect to Tempo Rest API using scripted field ?
Thanks a lot.
JamieA
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.
July 21, 2016

Don't use the rest API... you can use the java API. Our docs are mostly correct apart from the location of the WorklogAttributeService. I'll check it and get back to you.

Vladimir Voitechovic February 22, 2017

Hi Jamie,

Where can I find the method summary of the following classes:

com.tempoplugin.core.workattribute.api.WorkAttribute;
com.tempoplugin.core.workattribute.api.WorkAttributeService;
com.tempoplugin.core.workattribute.api.WorkAttributeValue;
com.tempoplugin.core.workattribute.api.WorkAttributeValueService;
com.tempoplugin.issue.service.IssueService;

And is it possible to get the TEMPO worklog object and then get the attribute's value of that log using Java API? We are using Tempo 7.15.0.

Thanks a lot,

 Vladimir

Jonny Carter
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.
February 23, 2017

Unfortunately, Tempo doesn't publish a JavaDoc, so there's not a good place to get their method summaries. The best you can do is point a tool like IntelliJ's decompiler at the tempo jar (you can unzip the downloadable .obr file that is on the marketplace) and see what you can divine that way.

Like Corentin Méhat likes this
Vladimir Voitechovic February 23, 2017

Hello Jonny,

Thank you for the answer. I just want to to clarify some things:

In your script above I see that you used methods from class workAttributeService (namely, getWorkAttributeByKey("_JobType_")) and workAttributeValueService (namely, getWorkAttributeValueByWorklogAndWorkAttribute(worklog.id, attribute.id)). Where did you find those methods? Can I use something similar to get the TEMPO worklog object and then get the attribute's value of that log using Java API? Jamie in his comment above mentioned about java API.

Also, I wrote more about the problem I want to solve here https://answers.atlassian.com/questions/56472295

 Thanks in advance,

Vladimir

Vladimir Voitechovic March 5, 2017

Hello,

Does anybody comment my question?

Thanks in advance,

Vladimir

0 votes
Mark McCormack _Adaptavist_
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.
July 21, 2016

Hi,

We have a new section in our ScriptRunner documentation that covers how to work with Tempo worklogs.

I hope it helps.

Regards, Mark.

JamieA
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.
July 21, 2016

our docs are for tempo 7, it won't work with tempo 8. We're working on that.

CST JIRA Confluence Admin July 21, 2016

Hi Jamie,

Here is the code I think can work with Tempo 8.0.0.2. But need to change something in the code. It doesn't work properly.

==========================================================

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.Worklog
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.tempoplugin.core.workattribute.api.WorkAttributeService

@WithPlugin("is.origo.jira.tempo-plugin")

@PluginModule
WorkAttributeService workAttributeService

def worklogManager = ComponentAccessor.getWorklogManager()
def worklogs = worklogManager.getByIssue(issue)

worklogs.findAll { worklog ->
workAttributeService.getWorkAttributeByKey("_OverTime_")
}
.sum { Worklog worklog ->
worklog.timeSpent
} as Long

// if no overtime worklogs just return null

===========================================================

Btw can above code get the worklog attribute value after modified ??

JamieA
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.
July 21, 2016

sorry - what do you mean by "after modified"?

CST JIRA Confluence Admin July 21, 2016

Sorry. My point is can I modify your code on docs to get work attribute value. Let me try the code of Johnny Carter.

0 votes
Susanne Götz [Tempo]
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.
July 21, 2016

Hi,

Since the release of Tempo Timesheets 8 it is possible to retrieve information about the worklog attributes via API (see http://tempo.io/doc/core/api/rest/latest/ for more information). 

Please note that this API is private and subject to change.

Regards,

Susanne

Suggest an answer

Log in or Sign up to answer