create automation task to send email when certain number of issues are created.
Asked by Jason Yeung:

Hi,

I'm currently using an add-on named Automation for JIRA in order to create the following automation rule:

When an issue is created, I want to check how many issues were created for this project and if there are more than 10, send an email out.

The trigger will be when the issue is created and I select new condition. What I want is for this section to check how many issues are assigned to the project. But I'm a bit stuck. I was wondering if there is JQL code that checks how many issues are created? For example, in SQL, I would type in something like:

SELECT COUNT(\*) FROM Issues WHERE (condition).

Sincerely,

Jason


Answers:
author: Darryl Lee
body: Because you mentioned using an add-on named [Automation for JIRA](https://marketplace.atlassian.com/apps/1215460/automation-for-jira-data-center-and-server?tab=overview&hosting=datacenter), you're probably running on Jira Data Center or Server, because in Cloud (which is what you've tagged your question), Automation is built-in.

Automation for Data Center and Server is very similar to Cloud, but as you discovered, it does not have a **Lookup Issues action**.

However if you are ok with there being up to a 24 hour delay in your notification, you could create a Scheduled trigger that runs every day, doing a JQL search as pictured in the [documentation here.](https://confluence.atlassian.com/automation/triggers-993924804.html)

You would want a query like:

```
project = YOURPROJECT
```

In Server, the count returned by the JQL query would be accessible via the Smart Value **{{issues.size}}** , as [documented here](https://confluence.atlassian.com/automation/smart-values-993924860.html).

But as [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) correctly points out, you might run into a limit on the number of issues returned.

++**I'm a little unclear as to your intent though.**++

You want a one-time notification when this project has \> 10 issues?

So like this?

![Screen Shot 2021-09-27 at 9.06.45 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/162364i68C1E4BFCD4C7E6D/image-size/large?v=v2&px=999 "Screen Shot 2021-09-27 at 9.06.45 PM.png")

I mean, if you implemented that rule, for every issues beyond the first 10, you would get an email.

That's probably NOT what you want.

++**Are you looking for an email for something like an email for every 10 new issues?**++

Then you probably would need to do some modulo operation.

The other thing I was thinking is if you could keep a running count of all issues in a Project Entity Property, and then you could just use the "Issue Created" (note that this Rule is scoped to a single project) trigger and increment the "totalissues" property by 1 every time.

So that would look something like this:

![Screen Shot 2021-09-27 at 9.22.33 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/162366i22DB10363E2BC0AA/image-size/large?v=v2&px=999 "Screen Shot 2021-09-27 at 9.22.33 PM.png")

comments: author: Jason Yeung
body: [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) ,

Thanks for your help and tips on this and also what issues may crop up. The main intent was initially to send an email to me of all projects that contain at least 10 issues, but I can see where it can lead to problems.

I can adjust it so that it would be a trigger that runs once a week to check what projects currently have at least 10 non-closed issues. An email will be sent that contains a list of these projects. If a project has at least 10 non-closed issues every week, then it will continue to appear in the email every week.

The email is mainly used to determine which projects we have to allocate more resources to, because of the number of issues currently active.

It's a bit similar to what you stated in the first scenario except it will run once a week and the project is not hard-coded (e.g. not always "rdp").

Sincerely,

Jason


author: Darryl Lee
body: AHHH, ok you're looking for projects that have at least 10 issues where **Resolution = EMPTY**

That makes a lot more sense, and yes, running this weekly would probably be good. Assuming folks are doing their jobs (or you aren't totally under-allocated on resources), you shouldn't hit the 100 issue limit. :-}

The thing is, I can't think of a way to do this without creating a separate rule for **every Project**.

That is, you can schedule a weekly task, but it will have to be with per project, so:

```
project = XYZ and Resolution = Empty
```

and another Rule with:

```
project = ABC and Resolution = Empty
```

Because I'm pretty sure you won't be able to extract different count totals for each project.

(There's no equivalent of GROUP BY in JQL.)


author: Darryl Lee
body: As [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) pointed out, there's no COUNT function, which would very helpful in your case, but I guess to put in SQL terms, you can only query ONE table with JQL, and that would be the "issues" table.

So that's why you'd have to have a different rule for each project. Because you'll always need to filter for issues in *just that project.*


author: Jason Yeung
body: Hi [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) and [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) ,

thanks for your help on this. I was able to figure this one out. What I did is in the schedule trigger, under "more options", I checked the "Process all issues produced by this trigger in bulk".

This would allow me to use the Smart value issues.size. I would add a new condition (if / else block) which checks the value of issues.size and if it's bigger than 10, send the email out.

Sincerely,

Jason


author: Darryl Lee
body: Glad to hear you got it working, [@Jason Yeung](/t5/user/viewprofilepage/user-id/4091080) ! Yes, I forgot about the "Process all issues" checkbox. Good that you found that.

So was I right in thinking you'll need one rule per Project? I couldn't think of any way around that.


author: Jason Yeung
body: [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) ,

Yes, it would be per project. It may be OK, as some projects we have may no longer be active and it would allow us to customize the emails for each project.

I though it could be tedious to create each rule 1 by 1. But I think I can create it once, export it and then reimport and customize it for a different project.

Jason


author: Darryl Lee
body: Ah yes, the joy of creating (and maintaining) multiples rules.

From the global**Automation Rules** interface (under Administration -\> System) you can *Copy* rules and change the project.

![Screen Shot 2021-10-01 at 9.42.41 AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/163111i12EFEF0F05237467/image-size/large?v=v2&px=999 "Screen Shot 2021-10-01 at 9.42.41 AM.png")

*Exporting* can be useful if you're comfortable hacking around in JSON. For something like this, it would actually be pretty straightforward to do a search and replace on the **projectId**, and bulk generate several rules that could then be imported.

(I have a big hairy article about this that I have to fix up and publish some day.)


author: Bill Sheboy
body: Hi [@Jason Yeung](/t5/user/viewprofilepage/user-id/4091080)

First thing, JQL is not a SQL, and so it has no aggregate operations like COUNT.

With an automation rule, you can use the [Lookup Issues action](https://support.atlassian.com/jira-software-cloud/docs/smart-values-general/#Smartvaluesgeneral---lookupIssues--) to gather the issues with your JQL, and then check count with the [list size](https://support.atlassian.com/jira-software-cloud/docs/smart-values-lists/#Smartvalueslists-list.size):

{{lookupIssues.size\|0}}

Please note: automation rules can only handle up to 100 issues at once, so if you have more than 100 the count will be incorrect.

Kind regards,  
Bill


author: Jason Yeung
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) ,

Currently I'm using Jira Server and I gather the lookup issue feature is only for Jira Cloud. Someone in the past asked about this (<https://community.atlassian.com/t5/Automation-questions/automation-and-lookup-issue/qaq-p/1415923>) and someone mentioned it's only for Cloud.

I was wondering if you know of an alternative to this action?

Sincerely,

Jason

comments: author: Bill Sheboy
body: Hi Jason,

I missed that you were on server with my first post. Sorry about that! Please take a look at the alternatives that Darryl posted for some ideas on how to do this with your version.

I'd also direct your attention to where he asks: what problem are you trying to solve? Knowing that context may help the community to offer additional suggestions. Thanks!

Kind regards,  
Bill


author: Jason Yeung
body: [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) ,

Thanks for your help. I tried setting a scheduled trigger, but then I tried to add an action, I couldn't find the Lookup Issues action. I get the following:

![jira_actions.JPG](https://community.atlassian.com/t5/image/serverpage/image-id/162355i2C51AD5D40437CFA/image-size/large?v=v2&px=999 "jira_actions.JPG")

I tried doing something similar to <https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Count-total-issues-with-same-category-then-compare-against-a/qaq-p/1512591>. She uses the lookup issues action as her second step, but I don't have this. I was wondering if there is another issue I could use? Or would I need a different version of the add-on?

Jason


Tags: cloud