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.
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(worklog.id, attribute.id).returnedValue
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
Where can I find the method summary of the following classes:
Thanks a lot,
Vladimir
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Does anybody comment my question?
Thanks in advance,
Vladimir
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
We have a new section in our ScriptRunner documentation that covers how to work with Tempo worklogs.
I hope it helps.
Regards, Mark.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
our docs are for tempo 7, it won't work with tempo 8. We're working on that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sorry - what do you mean by "after modified"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry. My point is can I modify your code on docs to get work attribute value. Let me try the code of Johnny Carter.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.