Hi Team,
my requirement is need to send the notification mail to all users available in 1,2 & 3 multi user picker fields and we need to trigger the mail daily
Kindly let me know any solution for this.
Thanks.
Hi @Ivan Tovbin , Sorry for the delay, now am trying to resolve this issue using Jobs option in script runner Plugin.
It seems the problem is in this line:
def id = ("Email Address: "+userSelected.getEmailAddress());
First off, the value doesn't really make much sense. Secondly if your want to use this variable outside of your cycle then you need to declare it outside first.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ivan Tovbin , Can you help to get the solution for this issue?
I tried to resolve this problem with so many ways but i couldn't found the exact template to get this. Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try the code I provided above, should do the trick
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ivan Tovbin , Now i have used your code which is provided above. but still it's not working. there are no errors in our code still emails are not getting triggered to users and got some error in log.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well that's because 'issues' variable is not declared in your script. As is 'emails' by the way. It looks like you took only a part of my code and expect it to work like this. It won't.
What you should do is configure a scripted job and make it run the code I provided in its entirety. Check this documentation for more info.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ivan Tovbin , Thanks for the replay.
just i have configure a new scripted job still showing some errors.
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.
A scripted service seems to be the solution here. Here's the logic:
1) Create a service that runs once at the start of each day (say 0005 am).
2) Make it run a JQL search using this query:
"Approver Date" >= startOfDay() AND "Approver Date" <= startOfDay(7)
This way it should only return issues which have less than one week remaining on their Approver Date.
3) If any such issues are found, collect the users from their respective fields and send them a custom notification.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ivan Tovbin
thanks for your response :)
how can i create a service in jira. can you more elaborate on this?
can we know the logic in B/W services and JQL. and how this logic will trigger the custom mails to users in a multi-picker field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please advise the version of Jira Server and Scriptrunner that you are using.
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 @RichardA
Sorry for the delay. The code for your service should look something like this:
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.mail.server.SMTPMailServer
import com.atlassian.query.Query
import com.atlassian.mail.Email
import javax.mail.Message
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName("userName")
String jql = "\"Approver Date\" >= startOfDay() AND \"Approver Date\" <= startOfDay(7)"
List<MutableIssue> issues = searchIssuesByJql(jql, user)
if (issues) {
List<String> fieldNames = ["Approver", "Manager", "Editor"]
List<CustomField> customFields = fieldNames.collect { ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(it) }
issues.each { issue ->
List<String> emails
customFields.each { customField ->
emails = emails + issue.getCustomFieldValue(customField).collect { it.getEmailAddress() }
}
if (emails) {
emails.each { email ->
String subject = "Some subject"
String body = "Some body"
sendEmail(email, subject, body)
}
}
}
}
List<MutableIssue> searchIssuesByJql(String jql, ApplicationUser searchingUser) {
JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
SearchService searchService = ComponentAccessor.getComponent(SearchService)
Query query = jqlQueryParser.parseQuery(jql)
SearchResults results = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
return results.getResults()
}
void sendEmail(String to, String subject, String body) {
Email email = new Email()
email.setTo(to)
email.setSubject(subject)
email.setBody(body)
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
Thread.currentThread().setContextClassLoader(Message.class.getClassLoader())
mailServer.send(email)
}
As you can see, you need to specify the username which will be used to run your jql search. You might also want to modify that jql query to narrow your search down as much as possible. And I suppose you could also modify the code so it sends one email to all concerned users at once, instead of sending each user a separate email, like it does now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This could be easily done with Automation for Jira, however looking at the tags you use scriptrunner. If that is your daily driver, somebody else has to answer this. If you are also using / willing to use Automation for Jira, then I'm happy to help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.