How to get value of Tempo Worklog Attribute

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

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

Hi,

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

I hope it helps.

Regards, Mark.

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

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 ??

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

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

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.

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.

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

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.

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

Hello,

Does anybody comment my question?

Thanks in advance,

Vladimir

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 -&gt;
    def attribute = workAttributeService.getWorkAttributeByKey("_Overtime_").returnedValue
workAttributeValueService.getWorkAttributeValueByWorklogAndWorkAttribute(worklog.id, attribute.id).returnedValue
}

overtimeLogs.sum { Worklog worklog -&gt;
    worklog.timeSpent
} as Long

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. 

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.

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?

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.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 2 hours ago in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

13 views 0 3
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