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

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 Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published 4 hours ago in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

26 views 0 2
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