JIRA Scripting, Plugin and Report Development, ScriptRunner & Tempo tips
Creating Tempo 8 Worklog using a ScriptRunner script
Written on August 9, 2016
2019 update: The code below no longer works with later versions of Tempo. Seems like the link on Adaptavist site below has been updated, so you can try that one. However now I highly recommend using the official Tempo REST API. It is definitely more stable than trying to call Tempo objects directly. Don’t worry about the deprecated comment at the worklogAttributes JSON array. It works all right.
Adaptavist has a nice example of how to create a worklog. However, after upgrading to Tempo 8, the API changed and simply passing a map of attribute names and values to the create() function was no longer supported.
So how do we do it in Tempo 8 when we want to specify worklog attributes?
Tell ScriptRunner that we want to work with Tempo and get instance of the TempoWorklogManager using the @WithPlugin and @PluginModule annotations:
Then we get the WorkAttribute by calling the WorkAttributeService. In this case, we’ll be setting a Tempo Account attribute:
After that, we get an instance of the WorkAttributeValue and set its value using a WorkAttributeValue.Builder class:
Finally, we’ll put the account attribute in an ArrayList and call tempoWorklogManager.create(). Here’s the complete script:
The create() function called in the script is deprecated, but works for now.
If you know of a better way of creating a worklog or have any feedback on the code, let me know.
Comments