Hello all! I am currently using this
({{issue.worklog.timeSpentSeconds.sum}} /3600) /8
in my automation which will pull worklogs on an issue and turn it into days and updating a custom field with that.
I need to pull worklogs just for this current year though...I am having trouble figuring out how to do that...any ideas?
For a question like this, context is important for the community to help. Please post the following:
Until we see those...
I do not know if the worklog smart value in automation rules has a limit for how many entries are available. Thus, you may want to experiment to confirm if the entire year can be returned.
If they are available, you could use the started attribute with smart value, list filtering to sum just the values for the year based on that date / time value. Here are some references to help do that:
If all of the values are not available, due to the paging limits, you could instead specifically query for the worklogs for the timeframe using the Send Web Request action to call the REST API endpoint: https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-worklogs/#api-rest-api-3-issue-issueidorkey-worklog-get
Please note that endpoint with filtering requires sending the date / time range as UNIX timestamps in milliseconds.
Kind regards,
Bill
Thanks for that information, @Natalie Franklin
FYI -- Please try to stay within one thread when responding. That will help others reading this question in the future know if there are multiple ways to solve it. Thanks!
Back to your question...
You show multiple ways to get the issue needed, so let's assume the rule trigger returns one issue and you want the sum of the time spent since the start of the current year.
After some quick testing, it appears the issue is already getting the worklog entries, and so the additional REST API call is not needed after all. This would work:
{{#=}}(0{{#issue.worklogs}}{{#if(started.isAfter(now.withDayOfYear(1).toStartOfDay))}}+{{timeSpentSeconds}}{{/}}{{/}})/3600{{/}}
How that works is:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you - didn't mean to do that...
Thank you so much for this! I had to tweak just a little and this gave me a successful calculation of days
{{#=}}(0{{#issue.worklogs}}{{#if(started.isAfter(now.withDayOfYear(1).toStartOfDay))}}+{{timeSpentSeconds}}/3600 {{/}}{{/}})/8{{/}}
Added in the /8
This is amazing :)
I did learn a lot about the Web Request through the process though
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome, and well done!
Please note my earlier note about the results coming back with this approach. Theoretically, {{issue.worklogs}} could contain up to 5000 entries, although I doubt that actually happens in a rule! (Everything else for rule data-loads has a 100 item limit.)
And so if you have over 100 worklogs for an issue within a year, this may stop working. You can test that as the year continues, writing this to the log to watch for problems: {{issue.worklogs.size}}
In that case, you may return to the REST API approach you learned. The REST API call could be filtered to only return entries during 2025 using the parameters I mentioned earlier using UNIX timestamps, and that will return up to 5000 entries. Those would be this, for the start and end of 2025:
{{#now}}func=withDayOfYear(1).toStartOfDay, format="toMillis"{{/}}
{{#now}}func=withMonth(12).endOfMonth,format="toMillis"{{/}}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello - thank you for your response.
I am trying to pull worklogs for a particular issue but only for this year. I have tried to use a web request. But I only need to grab the worklogs for the year starting with 2025. I THINK the way I need to go about this is use an if statement - maybe then be able to put those timeSpentSeconds into a variable then do a calculation on that variable?
For testing purposes I am trying to just comment on the ticket so I can see what is outputting.
The top pic is how I am currently calculating worklogs using this equation ({{issue.worklog.timeSpentSeconds.sum}} /3600) /8
this allows the seconds to be displayed in days or half days.
SO my end goal is to only calculate worklogs for 2025
Below is what I am currently testing with - I was using this comment before
{{#webResponse.body.fields.worklog.worklogs}}
Started: {{started}}
Time Spent Sec: {{timeSpentSeconds}}
{{/}}
and it was successfully giving me all worklogs on this issue - but how do I get just ones where Started contains 2025?
Right now this is not returning anything
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.