How to display all worklogs for the last week in the smart values?
Asked by Halyna Rudych:

Hi!

I am trying to use Jira Automation rule and send a scheduled email with the worklogs made within the last week however this filter seems not working.

I will appreciate your help!

I am using this email content.

{{#issues}}

{{#worklog}}

{{#if(now.minusWeeks(1).isBefore(created))}}

Issue: {{key}}

Summary: {{summary}}

Assignee: {{assignee.displayName}}

Worklog Author: {{author.displayName}}

Time Spent: {{timeSpent}}

Worklog Created: {{created.format("yyyy-MM-dd HH:mm")}}

{{/}}

{{/}}

{{/}}

JQL that is used to lookup the issues:

project = PROJECT_NAME AND type IN (Epic, Bug, Story, Task, Sub-task) AND worklogDate \>= startOfDay(-7d) ORDER BY created DESC


Answers:
author: Bill Sheboy
body: Hi [@Halyna Rudych](/t5/user/viewprofilepage/user-id/5052630)

For a question like this, please post an image of your complete automation rule, images of any relevant actions / conditions / branches, an image of the audit log details showing the rule execution, and explain what is not working as expected. Those will provide context for the community to offer ideas. Thanks!

Until we see those...

1) As described by [@Wojciech Wardaszko _HeroCoders_](/t5/user/viewprofilepage/user-id/4928380) the plural smart value {{issues}} is used by Jira Server and Data Center for bulk-issue handling, and is apparently not supported for Jira Cloud. IMO, any values you see from it are likely unsupported and unpredictable. Instead, try the [Lookup Issues action](https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Lookup-issues) to gather the issues for batch processing.

2) Also, when inside of an iterator such as {{#lookupIssues}} ... {{/}} the *issue.* prefix is not needed as the scope is the lookup results.

3) Next, do you want to check when the worklogs were **created** or **started** (when the person indicated the work happened)? For now, I will assume *started* as that defaults to the *created* value if *started* is not entered by a person.

Using Lookup Issues and the *worklog* smart value, you may use the *started* attribute for filtering on the date range. **Please note well** : according to the documentation, the worklog smart value is only used with the Work Logged trigger: <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/#--worklog--> However its seems to available for the more recent entries also. (To see older log entries, or when there are many log entries, a rule will need to [call the REST API with filtering on the timestamp, one issue at a time](https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issue-worklogs/#api-rest-api-3-issue-issueidorkey-worklog-id-get).)

Assuming you want to filter for the last 7 days (which is what your filter shows), you could try this expression:

```
{{#lookupIssues}}
{{key}} - {{summary}} assigned to {{assignee.displayName}}.
Worklogs in the last 7 days:
{{#worklog}}
{{#if(started.isAfter(now.minusWeeks(1).toDateTimeAtStartOfDay))}}
Time tracked by: {{author.displayName}}
Time spent: {{timeSpent}}
Worklog date & time: {{created.format("yyyy-MM-dd HH:mm")}}
{{/}}
{{/}}
{{/}}
```

Some things about this one:

* it does not handle unassigned issues; the value will be null for the assignee
* it does not handle no worklogs found for the last 7 days
* it does not handle time zone impacts for the week adjustment; however, I did adjust to the start of the date selected so the entire day is covered, regardless of when the rule is run relative to {{now}}

Kind regards,  
Bill


author: Wojciech Wardaszko _HeroCoders_
body: Hi [@Halyna Rudych](/t5/user/viewprofilepage/user-id/5052630),

I haven't tested it so I'm just speaking from my knowledge of how automation rules work, but IIRC the {{worklog}} smartvalue is only available when the trigger is set to Work Logged.

I'm also not sure about the {{#issues}}, I think you're looking for {{#lookupIssues}} since you referenced using the Lookup issues action with the JQL filter.  

You could try accessing {{#issue.worklogs}} inside the {{#lookupIssues}} loop, but you'd need to do it a little differently - you're trying to fetch things from different scopes all together.

Again, not tested, but I think something like this would have a better shot at working:

{{#lookupIssues}}  
{{key}} - {{summary}} assigned to {{assignee.displayName}}.  
Worklogs:  
{{#issue.worklogs}}  
{{#if(now.minusWeeks(1).isBefore(created))}}  
Time tracked by: {{author.displayName}}  
Time spent: {{timeSpent}}  
Worklog date \& time: {{created.format("yyyy-MM-dd HH:mm")}}  
{{/}}  
{{/}}  
{{/}}  

I hope this helps or at least guides you in the right direction.

Alternatively, you could just use our app, [Clockwork Free](https://marketplace.atlassian.com/apps/1220750/clockwork-automated-time-tracking-timesheets-free?hosting=cloud&tab=overview) or any [other free timesheet app](https://marketplace.atlassian.com/search?query=timesheet&price=paid) to get the necessary report without going through all this ;)

Cheers!

comments: author: Halyna Rudych
body: Hi [@Wojciech Wardaszko _HeroCoders_](/t5/user/viewprofilepage/user-id/4928380) ,

Thank you for your suggestion! Unfortunately, it didn't help. The problem is that this filter doesn't filter the worklogs correctly. Only this seems to be a problem, because when I am removing it at all then I receive an email with all worklogs.

{{#if(now.minusWeeks(1).isBefore(created))}}

I can't figure out why it doesn't work. I will appreciate your further help. Thanks!


author: Halyna Rudych
body: Hi [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313)! I noticed your extremely good expertise around this area and I was wondering if you could help. I will greatly appreciate it!


Tags: automation

jira-cloud

smart-value