Hi
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/" + worklog.id
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" + worklog.id)
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:
https://scriptrunner.adaptavist.com/4.3.0/jira/working-with-tempo.html
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.tempoplugin.worklog.attribute.WorklogAttributeService
@WithPlugin("is.origo.jira.tempo-plugin")
@PluginModule
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?
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thread thread = new Thread() {
public void run() {
//Do what needs to be done in a separate thread here.
};
thread.start();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 + " " + issueEvent.worklog.id + " " + workAttribute.getId())
i++;
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 p.rijst@avisi.nl?
If you're interested, I could share my code of updating insight objects.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.