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.
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
We have a new section in our ScriptRunner documentation that covers how to work with Tempo worklogs.
I hope it helps.
Regards, Mark.
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(
ServiceOutcome<WorkAttribute> getWorkAttributeByKey(String key);
ServiceOutcome<Collection<WorkAttribute>> getWorkAttributesByType(WorkAttributeType.Type type);
ServiceOutcome<Collection<WorkAttributeType>> getWorkAttributeTypes();
our docs are for tempo 7, it won't work with tempo 8. We're working on that.
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,
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.ComponentAccessorimport com.atlassian.jira.issue.worklog.Worklogimport com.onresolve.scriptrunner.runner.customisers.PluginModuleimport com.onresolve.scriptrunner.runner.customisers.WithPluginimport com.tempoplugin.core.workattribute.api.WorkAttributeService
@WithPlugin("is.origo.jira.tempo-plugin")
@PluginModuleWorkAttributeService 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"?
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
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(<a href="http://worklog.id" rel="nofollow noopener noreferrer">worklog.id</a>, <a href="http://attribute.id" rel="nofollow noopener noreferrer">attribute.id</a>).returnedValue
}
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.
_Overtime_
timespent
timeLogs == 0.
What did I wrong?
Where can I find the method summary of the following classes:
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.
It looks like you're new here. Sign in or register to get started.