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

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

1 answer

This widget could not be displayed.

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

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
Atlassian Summit 2018

Meet the community IRL

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

Learn more
Community showcase
Published yesterday in Marketplace Apps

The 7 hacks of highly successful automation

...there's anything I've learnt from working, it's that people are lazy! No offense to anyone reading this, but it's true and we can all admit it. The easier you make something for someone, the more...

291 views 0 13
Read article

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