Hi,
I have "Valid warranty date" Date field when it lesser than 2 days than system's date (i mean when warranty date expiring in two days) it should trigger an email to specific user.
I have this following code but not triggering an email
Could you help me on this.
Thank u in advance
import com.atlassian.jira.component.ComponentAccessor
import groovy.xml.MarkupBuilder
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
def warrantyField = customFieldManager.getCustomFieldObjectByName("Valid Warranty Date")
def warranty = issue.getCustomFieldValue(warrantyField)
def systemDate = new Date()
if(warranty < systemDate)
def sendEmail(String emailAddr, String subject, String body) {
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email(prasadhattaraki@gmail.com)
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")
}
}
Hello!
Why don't you use just a filter subscription? It should be quite easy:
1. Create a filter with a JQL to evaluate the warranty field between today and 2 days after;
2. Create a filter subscription to send an email at any time during the day.
I think it is much easier.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, it's basic functionality.
For example, in my organization, I added a special time field called "Scheduled action" not to forget about postponed tasks. Then I created a filter to find all tasks scheduled for today. The last step is to subscribe to this filter. That is all, without any coding. In the morning I received the letter on my work email with a list of all the issues that require my attention today.
If you have any specific questions I'm here to answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have "Valid Warranty Date" field , before 2 days of expiring warranty date it has to trigger email to specific user.
Could you help me in this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The first step for us is to create a right JQL to search the needed issues. It would be something like that:
project = <name of the project> AND "Valid Warranty Date" >= now() AND "Valid Warranty Date" < "2d"
This will give us the required list of issues.
We should save this filter and give it a name.
The final step is to subscribe to this filter. You can find it under "My filters":
Click on it and then "Subscription" or "Subscribe".
The final step is to create the subscription. On the screen below there's an "Edit" screen but parameters are the same:
You can choose the recipient (you can make it a group or an individual user). You can also specify the time when you want an email to be delivered.
Should you encounter any difficulties, please, don't hesitate to get back to me.
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.
It's "Greg" :)
Happy to help.
You might want to mark the answer as "Accepted" so that other users with the same question would find the solution easier.
Have a nice day!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Shivaprasad Hattaraki
Is this full code? Here you define function and doesnt use it.
I should be like this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.mail.Email
import com.atlassian.mail.server.SMTPMailServer
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
def warrantyField = customFieldManager.getCustomFieldObjectByName("Valid Warranty Date")
def warranty = issue.getCustomFieldValue(warrantyField)
def systemDate = new Date()
if(warranty < systemDate)
{
sendEmail("prasadhattaraki@gmail.com", "Test subject", "Test body")
}
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")
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Where do you write this code? You should see in the logs if you make it to the log.debug("Mail sent")
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.
You should debug your code and look for errors in the atlassian-jira.log file. Did you look there? Are there any errors? You defined the sendEmail function but you do not use it.
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.