Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira Automation - Worklogs for this year

Natalie Franklin January 31, 2025

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?

2 answers

1 accepted

3 votes
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2025

Hi @Natalie Franklin 

For a question like this, context is important for the community to help.  Please post the following:

  • an image of your complete automation rule in a single image,
  • images of any relevant actions / conditions / branches, and
  • an image of the audit log details showing the rule execution.

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

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 3, 2025

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:

 

Like Natalie Franklin likes this
Natalie Franklin February 4, 2025

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

Like Bill Sheboy likes this
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 4, 2025

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"{{/}}

 

0 votes
Natalie Franklin February 3, 2025

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
current.png

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?

test.png
Right now this is not returning anything

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events