How to add a comment from the email template of 'Send Custom Email'

Daniel Ehrlich September 14, 2017

Back in the good old days of JIRA 6.1.7 and ScriptRunner 2.1.16 we could add a comment to an issue from within the velocity mark up by adding something like

 

<%

def commentText = "Sent email - IR: Recursive DNS Server" + " - new issue " + issue.key + "."
componentManager.getCommentManager()?.create(issue, transientVars.context.caller, commentText, false)

%>

 

at the end.

Now that we are in the present day running JIRA 7.4.4 with ScriptRunner 5.1.4 this no longer works and no email is sent.

I have been beating my head against a wall to try and figure out how to do this.  None of the suggestions found via google or searching the Atlassian communities have worked. Does anyone have any suggestions?

Thank you.

-- Dan Ehrlich

2 answers

0 votes
Bohuslava Křížková December 7, 2020

Prosím o přidání do skupiny za GARE 3.C

0 votes
Thanos Batagiannis _Adaptavist_
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.
September 15, 2017

Hey Daniel,

ScriptRunner 2.1.16 ? wow!!

Lot of things changed since then :)

So now there is a Condition and Configuration field. In that field the script that will create a comment to the issue will be something like 

import com.atlassian.jira.component.ComponentAccessor

ComponentAccessor.commentManager.create(issue, transientVars.context.caller, "this is a text", false)

// do not forget to return true - because it is also confition field
true

You can also have a look at the relevant section in the documenation Additional Configuration in Emails

regards, Thanos

Daniel Ehrlich September 15, 2017

Well, that did not work for me.  In the Condition and Configuration box I already had

 

issue.issueType.name == 'Future IR Type' &&
cfValues['Threat Type']?.value == 'Suspicious' &&
cfValues['Sent Initial Email']?.value != 'Yes'

 

So I tried changing it to

 

import com.atlassian.jira.component.ComponentAccessor

if (issue.issueType.name == 'Future IR Type' &&
cfValues['Threat Type']?.value == 'Suspicious' &&
cfValues['Sent Initial Email']?.value != 'Yes') {
ComponentAccessor.commentManager.create(issue, transientVars.context.caller, "this is a text", false)
true
} else {
false
}

This gets me a big red X complaining about transientVars being undeclared and cannot find matching method com.atlassian.jira.issue.comments.commentManager#create.

I tried CommentManager.create also with the same result.  

Importing com.atlassian.jira.issue.comments.CommentManager did not help.

This also did not work (same big red X):

import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.getCommentManager()

if (issue.issueType.name == 'Future IR Type' &&
cfValues['Threat Type']?.value == 'Suspicious' &&
cfValues['Sent Initial Email']?.value != 'Yes') {
commentManager.create(issue, transientVars.context.caller, "this is a text", false)
true
} else {
false
}

 

At a total loss.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events