Send E-mail Notification after editing a specific custom field in issue edit screen

Sys Admin February 18, 2014

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

7 answers

0 votes
Sys Admin February 18, 2014

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

Sys Admin February 20, 2014

Could you please look into this ?

0 votes
Sys Admin February 18, 2014

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.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 -

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
0 votes
Sys Admin February 18, 2014

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
0 votes
Sys Admin February 18, 2014

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


0 votes
Sameera Shaakunthala [inactive]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 18, 2014

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.

0 votes
Sameera Shaakunthala [inactive]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 18, 2014

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)

0 votes
Sys Admin February 18, 2014

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

Suggest an answer

Log in or Sign up to answer