Hi,
Require to send an email to the reporter , assigner & groups once an issue meets certain criteria specified in a JQL query , ( Tried using Filter but not able to send mails to reporter , assigne of each issues ) , there is no event involved , so no transition is changed, so we were unable to use notification scheme for this ,
can anyone help in providing the Groovy Script for sending emails based on JQL.
also tried Script from https://answers.atlassian.com/questions/8619332/can-you-execute-a-search-filter-using-script-runner but getting errors while executing script
JIRA Version = 7.0.9
ScriptRunner Version = 4.2.0.7
Regards
Vijay
Community moderators have prevented the ability to post new answers.
Ok so you want either an escalation service, that will trigger an action (send email) or a service. Below is a sample script that you can use as a service. The first part will collect all the issues that returned from JQL in an array. The second part is a simple sendEmail function. You can modify the script to iterate through the issues and /*forEach do something*/
import com.atlassian.jira.bc.issue.search.SearchService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.web.bean.PagerFilter def issueManager = ComponentAccessor.getIssueManager() def searchService = ComponentAccessor.getComponent(SearchService) def jqlSearch = "project = JIRA" def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() // eventually this array will contain all the issues that returned from the JQL def issues = [] SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch) if (parseResult.isValid()) { def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()) issues = searchResult.issues.collect { issueManager.getIssueObject(it.id) } } // Create an email def sendEmail(String emailAddr, String subject, String body) { SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer() if (mailServer) { Email email = new Email(emailAddr) email.setSubject(subject) email.setBody(body) mailServer.send(email) log.debug("Mail sent") } else { log.warn("Please make sure that a valid mailServer is configured") } }
Hi,
This Script is working
it would be very helpful if Reporter, assinge of the tickets can be added while sending the email .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can get the reporter or the assignee (ApplicationUser) of the issue with
issue.getAssignee()
and his email address
issue.getAssignee().getEmailAddress()
same with the reporter or any other custom field which 'holds' users. From the moment you have the array with the issues and you iterate over them you can actually get any information an issue has (reporter, assignee, custom fields, ...).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Thanks for the script ,it working as expected
tried adding CC in email , but variable is unable to set for CC &BCC in email
def reporter = userUtil.getUserByName(issue.reporter.name);
def reporterEmail = reporter.getEmailAddress();
def reporterFirstName = reporter.displayName;
def assignee = userUtil.getUserByName(issue.assignee.name);
def assigneeEmail = assignee.getEmailAddress();
def assigneeFirstName = assignee.displayName;
Email email = new Email(reporterEmail) ; is working
Email email = new Email(reporterEmail to,assigneeEmail cc) ; is not working
email.setBody(content)
mailServer.send(email)
Followed the https://jamieechlin.atlassian.net/wiki/display/GRV/Post+Functions
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.
Hi @Thanos Batagiannis [Adaptavist],
Thanks for the support
email.setCc(
"aUser@example.com"
) is working perfectly ,
But
Email email =
new
Email(reporterEmail, assigneeEmail) is throwing error , Kindly find the attachment
Error.png
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sorry Vijay, I forgot to add the third argument. I updated the code above. the email constructor gets either one argument (to) or three (to, cc, bcc).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanos Batagiannis [Adaptavist], After adding the 3rd Argument am able send mail successfully ,
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Thanos Batagiannis [Adaptavist] Where to use this service? I mean we need to confiure few things i checked at the time of adding a service its asking for the Class name, what should i give.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Below is my JQL ,
For some of the Issues Update itself is not happening for more than some period .
issuetype = Incident AND ((Impact = Medium AND Urgency = HIGH) or(Impact = High and Urgency = Medium)) AND status not in (Closed, resolved) and updated < "-2h" and Email= No
issuetype = Incident AND ((Impact = Medium AND Urgency = HIGH) or(Impact = High and Urgency = Medium)) AND status not in (Closed, resolved) and updated < "-4h" and Email= No
issuetype = Incident AND ((Impact = Medium AND Urgency = HIGH) or(Impact = High and Urgency = Medium)) AND status not in (Closed, resolved) and updated < "-6h" and Email= No
issuetype = Incident AND ((Impact = Medium AND Urgency = HIGH) or(Impact = High and Urgency = Medium)) AND status not in (Closed, resolved) and updated < "-7h 35m" and Email= No
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vijay,
How your JQL looks like ? I understand that because you do not transition the issue you can't use a post function. Did you try to use an event listener ? (that listens on issue update events)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.