How to send email notification to 2 users if the custom field value hasn't been provided within 5 calendar days of creation of task.
I have a script runner plugin so open to use any solution like script listener or Jobs.
Any advice would be greatly appreciated.
Thanks,
Om.
thanks for your question. This is something I would usually achieve using Automation rules.
If you want to use ScriptRunner, Jobs would be the recommended way to go. There you would configure a scheduled job that scans periodically.
In the script part you would need to search for issues in your project with that field missing.
After that, check each returned issue for your field and sent an email to the users.
I would recommend browsing through the Adaptavist Script Library to get a little inspired 🙂
I just tried finding the tickets which are missing the value even after 5 days.
Using Jobs in script runner.
JQL query that I am using.
project = PROJ-A AND issuetype = "Change Request" and "Estimated hours)" is empty and (createdDate <=startOfDay(-4d) and createdDate >= startOfDay(-5d))
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
import com.atlassian.mail.queue.MailQueue
import com.atlassian.mail.queue.SingleMailQueueItem
MailServerManager mailServerManager = ComponentAccessor.getMailServerManager()
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer()
if (mailServer) {
////////////////////Set the Email Variables//////////////////////////////////
///////TO: Email Address////////
def ToEmailAddr = "firstname.lastname@email.com"
// def ToEmailAddr = issue.assignee.emailAddress
Email email = new Email("" + ToEmailAddr)
///////FROM: Email Address////////
email.setFrom("DoNotReply@jira.com")
///////Email Subject////////
email.setSubject("($issue.key) - $issue.summary")
// email.setCc("firstname.lastname@email.com")
email.setCc("firstname.lastname@email.com")
///////Set the Email Mime Type/////
email.setMimeType("Text/Plain");
///////Email Body////////
String content
content= "Dear "
content = content+
"\n"
content = content+
"Your ticket ($issue.key) Estimated hrs(Vendor) hasn’t been provided within 5 calendar days of creation"
content = content+
"\n\n\nSincerely," +
"\n" +
"Jira Admin"
email.setBody(content)
///////SEND Email ////////
SingleMailQueueItem smqi = new SingleMailQueueItem(email);
ComponentAccessor.getMailQueue().addItem(smqi);
}else {
log.error "No SMTP mail server defined"
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you need to search for the issues in the groovy script. So you will need to build in something like this:
Issues.search('PUT YOUR JQL HERE').each { issue ->
// your email logic is triggered here
}
Your JQL looks a little wrong I think. The Esitmated hours part needs a fix for the parentheses and I'm not sure about your project key, but this might be an example?
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.