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

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

This widget could not be displayed.

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

This widget could not be displayed.

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)

This widget could not be displayed.

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.

This widget could not be displayed.

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


This widget could not be displayed.

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
This widget could not be displayed.

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
This widget could not be displayed.

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

Could you please look into this ?

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

196 views 3 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you