We have a customfield namely "Call Type". We need jira mail notication whenever a value of this customfield is changed. I have used following script in "behaviour" for this purpose but it is not working -
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
import org.apache.log4j.Category
FormField "Call Type" = getFieldById(fieldChanged)
ComponentManager componentManager = ComponentManager.getInstance()
MailServerManager mailServerManager = componentManager.getMailServerManager()
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email("someuser@example.com") // Set the TO address, optionally CC and BCC
email.setSubject("Blocking issue raised by ${issue.getReporter().getFullName()}: ${issue.summary}") // todo: check the subject value
String content = "Construct your body here."; //TODO: Set email's body.
email.setBody(content)
mailServer.send(email)
}
else {
log.error("No SMTP mail server defined")
}
It gives us below mentioned error -
Compilation failure: startup failed: Script1.groovy: 14: unexpected token: Call Type @ line 14, column 11. FormField "Call Type" = getFieldById(fieldChanged) ^ 1 error
Could you please help us regarding this ?
Regards
Sumit
I have changed my code as per your suggestion. Still no luck. Please find my Code below -
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.mail.Email
import com.atlassian.mail.server.managers.OFBizMailServerManager
import com.atlassian.mail.server.SMTPMailServer
import org.apache.log4j.Category
FormField call_type= getFieldById(fieldChanged)
ComponentAccessor ComponentAccessor = ComponentAccessor.getInstance()
OFBizMailServerManager mailServerManager = ComponentAccessor.getOFBizMailServerManager()
SMTPMailServer mailServer = OFBizMailServerManager.getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email("system-admin@nrifintech.com") // Set the TO address, optionally CC and BCC
email.setSubject("Blocking issue raised by ${issue.getReporter().getFullName()}: ${issue.summary}") // todo: check the subject value
String content = "Construct your body here."; //TODO: Set email's body.
email.setBody(content)
mailServer.send(email)
}
else {
log.error("No SMTP mail server defined")
}
Now below mentioned error showing -
Compilation failure: startup failed: Script1.groovy: 7: unable to resolve class com.atlassian.mail.Email @ line 7, column 1. import com.atlassian.mail.Email ^ Script1.groovy: 8: unable to resolve class com.atlassian.mail.server.managers.OFBizMailServerManager @ line 8, column 1. import com.atlassian.mail.server.managers.OFBizMailServerManager ^ Script1.groovy: 9: unable to resolve class com.atlassian.mail.server.SMTPMailServer @ line 9, column 1. import com.atlassian.mail.server.SMTPMailServer ^ Script1.groovy: 5: unable to resolve class com.atlassian.jira.ComponentAccessor @ line 5, column 1. import com.atlassian.jira.ComponentAccessor ^ 4 errors
I have changed my code as per your suggestion. Still no luck. Please find my Code below -
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
import com.onresolve.jira.groovy.user.FieldBehavioursimport com.onresolve.jira.groovy.user.FormFieldimport com.atlassian.jira.ComponentAccessorimport com.atlassian.jira.issue.Issueimport com.atlassian.mail.Emailimport com.atlassian.mail.server.managers.OFBizMailServerManagerimport com.atlassian.mail.server.SMTPMailServerimport org.apache.log4j.Category FormField call_type= getFieldById(fieldChanged)ComponentAccessor ComponentAccessor = ComponentAccessor.getInstance()OFBizMailServerManager mailServerManager = ComponentAccessor.getOFBizMailServerManager()SMTPMailServer mailServer = OFBizMailServerManager.getDefaultSMTPMailServer() if (mailServer) { Email email = new Email("system-admin@nrifintech.com") // Set the TO address, optionally CC and BCC email.setSubject("Blocking issue raised by ${issue.getReporter().getFullName()}: ${issue.summary}") // todo: check the subject value String content = "Construct your body here."; //TODO: Set email's body. email.setBody(content) mailServer.send(email) }else { log.error("No SMTP mail server defined") } |
Now below mentioned error showing -
|
1
|
Compilation failure: startup failed: Script1.groovy: 7: unable to resolve class com.atlassian.mail.Email @ line 7, column 1. import com.atlassian.mail.Email ^ Script1.groovy: 8: unable to resolve class com.atlassian.mail.server.managers.OFBizMailServerManager @ line 8, column 1. import com.atlassian.mail.server.managers.OFBizMailServerManager ^ Script1.groovy: 9: unable to resolve class com.atlassian.mail.server.SMTPMailServer @ line 9, column 1. import com.atlassian.mail.server.SMTPMailServer ^ Script1.groovy: 5: unable to resolve class com.atlassian.jira.ComponentAccessor @ line 5, column 1. import com.atlassian.jira.ComponentAccessor ^ 4 errors |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have changed my code as per your suggestion. Still no luck. Please find my Code below -
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.mail.Email
import com.atlassian.mail.server.managers.OFBizMailServerManager
import com.atlassian.mail.server.SMTPMailServer
import org.apache.log4j.Category
FormField call_type= getFieldById(fieldChanged)
ComponentAccessor ComponentAccessor = ComponentAccessor.getInstance()
OFBizMailServerManager mailServerManager = ComponentAccessor.getOFBizMailServerManager()
SMTPMailServer mailServer = OFBizMailServerManager.getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email("system-admin@nrifintech.com") // Set the TO address, optionally CC and BCC
email.setSubject("Blocking issue raised by ${issue.getReporter().getFullName()}: ${issue.summary}") // todo: check the subject value
String content = "Construct your body here."; //TODO: Set email's body.
email.setBody(content)
mailServer.send(email)
}
else {
log.error("No SMTP mail server defined")
}
Now below mentioned error showing -
Compilation failure: startup failed: Script1.groovy: 7: unable to resolve class com.atlassian.mail.Email @ line 7, column 1. import com.atlassian.mail.Email ^ Script1.groovy: 8: unable to resolve class com.atlassian.mail.server.managers.OFBizMailServerManager @ line 8, column 1. import com.atlassian.mail.server.managers.OFBizMailServerManager ^ Script1.groovy: 9: unable to resolve class com.atlassian.mail.server.SMTPMailServer @ line 9, column 1. import com.atlassian.mail.server.SMTPMailServer ^ Script1.groovy: 5: unable to resolve class com.atlassian.jira.ComponentAccessor @ line 5, column 1. import com.atlassian.jira.ComponentAccessor ^ 4 errors
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have changed my code as per your suggestion. Still no luck. Please find my Code below -
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.mail.Email
import com.atlassian.mail.server.managers.OFBizMailServerManager
import com.atlassian.mail.server.SMTPMailServer
import org.apache.log4j.Category
FormField call_type= getFieldById(fieldChanged)
ComponentAccessor ComponentAccessor = ComponentAccessor.getInstance()
OFBizMailServerManager mailServerManager = ComponentAccessor.getOFBizMailServerManager()
SMTPMailServer mailServer = OFBizMailServerManager.getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email("system-admin@nrifintech.com") // Set the TO address, optionally CC and BCC
email.setSubject("Blocking issue raised by ${issue.getReporter().getFullName()}: ${issue.summary}") // todo: check the subject value
String content = "Construct your body here."; //TODO: Set email's body.
email.setBody(content)
mailServer.send(email)
}
else {
log.error("No SMTP mail server defined")
}
Now below mentioned error showing -
Compilation failure: startup failed: Script1.groovy: 7: unable to resolve class com.atlassian.mail.Email @ line 7, column 1. import com.atlassian.mail.Email ^ Script1.groovy: 8: unable to resolve class com.atlassian.mail.server.managers.OFBizMailServerManager @ line 8, column 1. import com.atlassian.mail.server.managers.OFBizMailServerManager ^ Script1.groovy: 9: unable to resolve class com.atlassian.mail.server.SMTPMailServer @ line 9, column 1. import com.atlassian.mail.server.SMTPMailServer ^ Script1.groovy: 5: unable to resolve class com.atlassian.jira.ComponentAccessor @ line 5, column 1. import com.atlassian.jira.ComponentAccessor ^ 4 errors
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you please convert your post to a comment to my answer? So it will be easier to keep track of discussion.
Seems you have imported the wrong package.
Looking at the developer docs, I find only one path under 'com.atlassian.mail...' hierarchi.
Can you import 'com.atlassian.mail.server.managers.OFBizMailServerManager' instead of 'com.atlassian.mail.server.MailServerManager' ?
I believe this should work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like a variable declaration problem. Can you please try it like this (line #12),
FormField call_type = getFieldById(fieldChanged)
(replace "Call Type" by call_type everywhere)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sameera,
After changing following error occured -
Compilation failure: startup failed: Script1.groovy: 7: unable to resolve class com.atlassian.mail.Email @ line 7, column 1. import com.atlassian.mail.Email ^ Script1.groovy: 8: unable to resolve class com.atlassian.mail.server.MailServerManager @ line 8, column 1. import com.atlassian.mail.server.MailServerManager ^ Script1.groovy: 9: unable to resolve class com.atlassian.mail.server.SMTPMailServer @ line 9, column 1. import com.atlassian.mail.server.SMTPMailServer ^ Script1.groovy: 5: unable to resolve class com.atlassian.jira.ComponentAccessor @ line 5, column 1. import com.atlassian.jira.ComponentAccessor ^ 4 errors
Regards
Sumit
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.