Hello,
I have an email automation that I use to send a weekly report. I have a jql that gathers all the results. If the status is closed it will list the results in a table. This has been working perfect! But when there is a table with no results I would like it to say "None"
This is the code I'm using
I've attempted to add {{#if(equals(lookupIssues.size,0))}} But it's not working.
Any suggestions?
------------------------------------------------------------------
<table >
<tbody>
<tr>
<th colspan="7" style="background-color: #AAD5FF; Padding: 10px" >Closed items for Week Ending - {{now.minusBusinessDays(1).longDate}}</th>
<tr/>
<tr>
<th style="background-color: #DDEEFF"><b>Epic Link</b></th>
<th style="background-color: #DDEEFF"><b>Key</b></th>
<th style="background-color: #DDEEFF"><b>Summary</b></th>
<th style="background-color: #DDEEFF"><b>Document Link</b></th>
<th style="background-color: #DDEEFF"><b>Comments</b></th>
<th style="background-color: #DDEEFF"><b>Assignee</b></th>
<th style="background-color: #DDEEFF"><b>Updated</b></th>
</tr>
{{#if(equals(lookupIssues.size,0))}}
<tr>
<td colspan="7" style="text-align:center;font-weight:bold;">None</td>
</tr>
{{/}}
{{#Issues}}
{{#if(equals(status.name, "Closed"))}}
<tr>
<td>
<a href="{{epic link.url}}">{{epic link.epic name}}</a></td>
<td>{{Key}} </td>
<td>{{summary}}</td>
<td><a href="{{epic link.Document Link}}">{{epic link.epic name}}</a></td>
<td>{{customField_11726}}</td>
<td>{{Assignee.displayName}}</td>
<td>{{Updated.shortDate}}</td>
</tr>
{{/}}
{{/}}
</tbody>
</table> </div>
Thank you @Varun Chillamcharla
So my jql (see below) actually gets a list of items, Approved item and then Tasks that include Requirements Completed, in the summary. In the email I have two tables
Table 1. Lists all of the Tasks
Table 2. All of the Approved Items
Because this works well I'm afraid to change it!
(project in (60740)) AND status changed from CANDIDATE to (APPROVED) during (startOfWeek(-1), endOfWeek(-1)) AND status not in (Implemented, Rescinded, Candidate) OR summary ~ "\"Requirements Completed\"" AND issueFunction in issuesInEpics("status in (Approved, Implemented) ") AND resolved >= startOfWeek(-1) AND updated <= endOfWeek(-1))
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.
Varun's read on the mismatch is right, and there's a small syntax thing that will make his fix look like it didn't work.
Text functions take parentheses, list functions don't, and it catches people out. The docs show text as "{{issue.summary.length()}} -> 12" and "{{issue.summary.isEmpty()}} -> false", while the list forms appear bare: "This bug has {{issue.issuelinks.size}} related tickets" and "{{#if(not(issue.issuelinks.isEmpty))}}". Your taskCount is a string, so it wants taskCount.length() with the brackets. Across that page the bracketed form is the only one shown, and the list page shows only the bare form, so the split holds throughout the docs rather than in a single example.
If your JQL already returns only what the table should show, you can skip the counting variable entirely and use the list form directly: {{#if(lookupIssues.isEmpty)}}None{{/}}. The counting approach earns its keep only when you filter inside the loop, which is the case Varun spotted in your template.
The thing I'd check before either, though, since it changes what any of these counts mean. The Lookup action reads at most 100: "When entering a JQL query for the Lookup work items action, only the first 100 work items will be used", and the action's own description is "Search for up to 100 work items using a JQL query." It doesn't warn you when it hits that. It stops. On a weekly report that's fine until a busy week quietly loses rows, and a count built on the truncated list will agree with the truncated table, so the two will look consistent while both being short. Run the same JQL in the issue navigator once and compare its total against what the email prints.
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.
Hello @Melissa C , the condition is close, and it fails for one reason worth knowing because it bites everywhere in automation: when a Lookup work items action returns no rows, {{lookupIssues.size}} is empty (null), not 0. So {{#if(equals(lookupIssues.size,0))}} compares nothing to zero and is never true, and your "None" branch never renders.
The fix is to give the size a default before comparing:
{{#if(equals(lookupIssues.size|0,0))}}
None
{{/}}
{{#if(lookupIssues.size.gt(0))}}
<table>
<tr><th>Key</th><th>Summary</th><th>Status</th></tr>
{{#lookupIssues}}
<tr><td><a href="{{url}}">{{key}}</a></td><td>{{summary}}</td><td>{{status.name}}</td></tr>
{{/}}
</table>
{{/}}
The |0 is the default-value operator: empty becomes 0, and the comparison works. The second block is guarded separately so the table markup only renders when there is something to put in it (an empty {{#lookupIssues}} loop inside a table is what leaves you with a header row and nothing under it).
Two equivalent forms if you prefer them: {{#if(lookupIssues.isEmpty)}}None{{/}} uses the documented list function (smart values for lists), and if you would rather branch in the rule than in the template, an If/else block with an advanced compare condition on {{lookupIssues.size|0}} equals 0 lets you send two different emails instead of one template with both branches.
One caution on the loop itself: only a limited set of fields is available inside {{#lookupIssues}} (summary, status, assignee, key and a few others; most custom fields, labels and components are not), so if a column comes back blank inside the table, that is the cause rather than the conditional (Atlassian KB on empty smart values). Conditional-logic reference: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/
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.