How to count the number of issues assigned to individual users of a project Edited

I need to trigger an email to the individuals assignees of a project along with their issues count. please provide me the script.

1 answer

This widget could not be displayed.

You could create a filter for "assigned to currentUser() and resolution is empty" and then get each of them to subscribe to it.

@Nic Brough [Adaptavist]

Thanks for the reply, but i want the data like something below -

Hi (Assignee name),

For the "project", there are (count of issues) assigned to you. Have a look at these issues by clicking on the below link-

          "The URL of the issues" .

I want to trigger an email so how to use the filter?

It's not hard to write a script that will run JQL and do things with the results, including sending mails out.

I'm not sure how I would write this, as you've not defined when you want to run it (every morning would probably be of most use to the users, without spamming them all day)

@Nic Brough [Adaptavist]

Hi Nic,

Correct probably once in a day , can you please help me out with this.

@Nic Brough [Adaptavist] 

Note - We are using the cloud version of Jira

Well, the basics are http://scriptrunner-docs.connect.adaptavist.com/jiracloud/scheduled-jobs.html but I don't think you can write "email people" scripts in Cloud.

@Nic Brough [Adaptavist]

Thanks for the reply, but how to get the count of issues assigned to each idividual.

@Shrikant Maheshwari @Nic Brough [Adaptavist]

Were you able to get the issue count for each assignee from JQL using groovy.  I can get the total issue count from the JQL, but i am looking for individual assignee issue count. I am running this as services. Please help.

Regards,

Deepali 

You would need one JQL query per assignee.  Or use "assignee = currentUser()"

package examples.docs
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.mail.Email;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.user.ApplicationUser

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def issueManager = ComponentAccessor.getIssueManager()
//def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
UserUtil userUtil = ComponentAccessor.getUserUtil()
//User user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ApplicationUser user = userUtil.getUserByKey("abc");
log.error("User: " + user)


// edit this query to suit
def query = jqlQueryParser.parseQuery("Status in (open, PMR) AND fixVersion is EMPTY AND category = HyperWorks AND createddate < -2w AND issuetype = 'Role Mapper' AND project != 'QA Mainline Validation' AND 'PM Reviewed' is EMPTY AND assignee in (dbagul, scottg)")

//def query = jqlQueryParser.parseQuery("project = Hm and assignee = dbagul AND statusCategory != Done")
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
log.error("results count: " + results.getTotal())

def tickets = results.issues.collect { issueManager.getIssueObject(it.id) }
// log.error("tickets: " + tickets)

def filterUrlLink = "https://jira.abc.com/issues/?filter=30835"
//Result of JQL

def pmFieldValues = []
def assignee

// if you need a mutable issue you can do:
for (Issue issue in tickets) {
issue = issueManager.getIssueObject(issue.getId())
assignee = issue.getAssignee().getEmailAddress()

if(assignee != null){
log.error("Adding assignee: " + assignee)
pmFieldValues += assignee
}
}

// log.error("pmFieldValues: " + pmFieldValues)

def subject = "JIRA ACTION REQUIRED: Open tickets require PM attention"
log.error(subject)
//def body = "This week you have "+ count + " open issues that have not been addressed for more than two weeks." +"\n"+ "Please review, prioritize and process accordingly."+ "\n" + "Use the following JIRA filter to report open issues that are at least two or more weeks old:" +"\n" + "JIRA Search:" + "\n" + filterUrlLink + "\n" + "\n" + "Regards," + "\n" + "Michael Dambach"
def emailAddr = pmFieldValues.unique()

log.error("emailAddr: " + emailAddr)


def sendEmail(String assigneeEmail, String subject, String body) {
log.error("In sendEmail method")
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer();
if (mailServer) {
Email email = new Email(assigneeEmail);
email.setFrom("abc@abc.com")
email.setSubject(subject);
email.setBody(body);
mailServer.send(email);
log.error("Mail sent")
} else {
// Problem getting the mail server from JIRA configuration, log this error
log.error("sendEmailInactiveIssues - Error sending email!")
}
}

//log.error('I am here')

for (String assigneeEmail : emailAddr) {
log.error('Each assignee issue count email')

def jqlQuery = "assignee=\""+ assigneeEmail.split('@')[0]+ "\" and Status in (open, PMR) AND fixVersion is EMPTY AND category = hyperWorks AND createddate < -2w AND issuetype = 'Role Mapper' AND project != 'QA Mainline Validation' AND 'PM Reviewed' is EMPTY "
def query1 = jqlQueryParser.parseQuery(jqlQuery)
def results1 = searchProvider.search(query1, user, PagerFilter.getUnlimitedFilter())
def count = (results1.total)
log.error(count)
def body = "This week you have "+ count + " open issues that have not been addressed for more than two weeks." +"\n"+ "Please review, prioritize and process accordingly."+ "\n" + "Use the following JIRA filter to report open issues that are at least two or more weeks old:" +"\n" + "JIRA Search:" + "\n" + filterUrlLink + "\n" + "\n" + "Regards," + "\n" + "Michael Dambach"
log.error(body)

sendEmail (assigneeEmail, subject, body)
}


 Thanks @Nic Brough [Adaptavist] I was able to send email to each assignee with their issue count in the email body. Above is the code which will be helpful for others. 

Regards,

Deepali Bagul

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

717 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you