Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

When Assignee is changed, would it be possible to send notification to both the old And new assignee

saroja muninaga October 22, 2018


Need to send notification to both old and new assignee when assignee has changed in jira

1 answer

1 vote
Alexey Matveev
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.
October 22, 2018

Hello,

You could do it with a scripting add-on.

For example, you could use the Power Scripts add-on.

https://marketplace.atlassian.com/apps/43318/power-scripts-jira-script-automation?hosting=cloud&tab=overview

If you change an assignee, the new assignee will receive an out of the box notification from Jira.

To send a notification to the previous assignee, you could create a listener on the Issue Assigned event and attach to this listener the following script:

string [] h = fieldHistory(key, "assignee"); 
string a; if(isNotNull(h[1])) {    
  a = h[1];
}
else
{    
  a = h[3];
} 

sendEmail(a, "teamleader1", "Assignee changed", " Assignee for issue:" + key + "has changed to " + assignee);

You can find more info on sendEmail method here:

https://confluence.cprime.io/display/SIL/sendEmail

saroja muninaga October 22, 2018

Hello @Alexey Matveev

Thanks for your reply .

I tried through script runner post function to send an email  .But getting error on sendEmail method .

import com.atlassian.mail.Email;
import com.atlassian.mail.server.MailServerManager;
import com.atlassian.mail.server.SMTPMailServer;
import com.atlassian.jira.component.ComponentAccessor;

def subject = "Insert text here for ${issue.key}"
def body = "Hi ${issue.assignee.displayName} \n\nNow that XXXXX has been released, please complete XXXXX for the following issue: https://XXXXXXX/${issue.key} - ${issue.summary}. \n\n"
// Gather changed field at the Issue Updated
def field = event.getChangeLog().getRelated('ChildChangeItem').find{it.field == "assignee"}

// Gather old field value
def old_field_value = field.oldstring

// Gather new field value
def new_field_value = field.newstring
def emailAddr = old_field_value

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);
} else {
// Problem getting the mail server from JIRA configuration, log this error
}
}
sendEmail (emailAddr, subject, body)

//Can not find matching method error is coming .

Thanks in advance. 

saroja muninaga November 29, 2018

Still i am facing same issue .please suggest any one ,how we can do using script runner plugin 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events