Conditional logic in email template for LookupIssues and Smart Value
Asked by Julian Petrich:

I want to create a Jira automation rule which sends out an email to each assignee based on a JQL query. The email should only contain a list with all issues assigned to the recipient.

Therefore, I created this automation:

![Screenshot 2023-08-24 at 1.30.50 pm.png](https://community.atlassian.com/t5/image/serverpage/image-id/276808i4B70A7FB1BEBDFCB/image-dimensions/228x361?v=v2 "Screenshot 2023-08-24 at 1.30.50 pm.png")

And my email template looks like this:

```
{{#lookupIssues}}
{{if(equals(issue.assignee, issue.distinctAssignee))}}
<a href="https://jira-url/{{key}}">{{key}} {{summary}} </a> <i>[{{status.name}}]</i>
{{/}}
```

**Problems:**

* The "if" statement is always true so every person I sent this email to gets a full list of all issues based on the JQL query.
* Sending out the email, it prints "true" in front of each issue I am listing.

Please let me know if you need any further information.

Help is much appreciated. Thank you!


Answers:
author: Darryl Lee
body: Hi [@Julian Petrich](/t5/user/viewprofilepage/user-id/5300217) -

How are you creating your list of "distinctAssignees"? Because as far as I know [that is not something](https://community.atlassian.com/t5/Jira-questions/JQL-distinct-or-unique-clause/qaq-p/1097192) you can get from a JQL lookup.

The other problem is that even if you had a way to create a list (manually using split()? API call?), the problem is [you cannot reference a Smart value from inside of a list iterator](https://community.atlassian.com/t5/Jira-Software-questions/Automation-Use-smart-value-inside-list-iterator/qaq-p/2011919).

In other words, {{distinctAssignee}} cannot be accessed from within the {{#lookupIssues}} iterator.

I think the approach you'll want to take is detailed here:

* [How to iterate over a created variable](https://community.atlassian.com/t5/Automation-questions/How-to-iterate-over-a-created-variable/qaq-p/2069507)

So you would put your Lookup ***inside*** of your Smart value branch, and modify your JQL to be:

```
project = 11844 AND type="finding" AND resolution is empty AND assignee={{distinctAssignee}}
```

Then all of the {{#lookupIssues}} should be the ones you want for each assignee, and you don't need to use **if** to filter them at all.

comments: author: Julian Petrich
body: Hi [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322)

Thank you for your help! That makes sense.

This is how I am getting my distinct assignees but maybe that's not even the best way to do it:![Screenshot 2023-08-24 at 3.19.56 pm.png](https://community.atlassian.com/t5/image/serverpage/image-id/276819i84DF7C75F5E7A29B/image-size/large?v=v2&px=999 "Screenshot 2023-08-24 at 3.19.56 pm.png")

I have tried your suggestion with another JQL query inside my Smart value branch which worked for a small amount of assignees. Once I changed the scope to all the assignees I got this error message:

[*Payload for custom variable is too large, try reducing the amount of data stored in your custom smart variable.*](https://community.atlassian.com/t5/Jira-Software-questions/Automation-Payload-for-custom-variable-is-too-large/qaq-p/2365371)


author: Darryl Lee
body: OH SHOOT, there is a [**distinct**](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/#list.distinct). Nice!

Huh. That is a weird error. When you say you had a small amount of assignees, do you mean you scoped the **first** Lookup to only include certain assignees?

I guess first off, how many issues are we talking about in the original query?

And how many distinct assignees are there?

(You could log **{{lookupIssues.assignee.distinct.size}}** to find out.)


author: Julian Petrich
body: Yeah, so in the initial lookup I had only myself and a colleague as assignees to test it the rule which worked perfectly.

The query has 142 issues and 24 distinct assignees.

The main reason to have this rule is that we close and open issues going into this query. Hence, I don't want to update and send emails manually.

My current workaround is to include a filter into my email with the query above and "assignee=currentUser()".


author: Darryl Lee
body: Bizarre. The custom smart variable the first time around is 24 assignees.

So you started getting the error when you added another Lookup for:

```
project = 11844 AND type="finding" AND resolution is empty AND assignee={{distinctAssignee}}
```

So like, 24 times, it should run that query and each time it should return a set of issues that is easily \< 142, so... I don't know.

Maybe this is a question for Support?


author: Julian Petrich
body: Yes, correct. So my second lookup was within the new branch. I was surprised as well.

Sure, I will reach out to the support then.

Thanks a lot for your support [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) it's good to know that it should work at least.