Accessing Comment ID in Custom Email Condition via ScriptRunner

Chris Knight July 28, 2015

I started using Script Runner (specifically Send a custom email) to work around the poor email notifications in JIRA Service Desk. So far it has worked well. The only struggle I have is with notifying users when comments are added. In Service Desk, there are internal and external comments. I want to be able to send a custom email to the reporter only when an external comment is added and include the text of that comment.

I've struggled with this a bit, but here's what I've found:

  1. Service Desk comment visibility is available via the API: https://answers.atlassian.com/questions/12159156
  2. I can query the API for a particular comment ID and get the JSON property

    https://jira/rest/api/2/comment/12171/properties/sd.public.comment/

    returns

    {"key":"sd.public.comment","value":{"internal":true}}
  3. In the Script Runner console, I can get a true/false value on whether a comment is internal or not:

    def curl = "/usr/bin/curl -u admin:admin https://jira/rest/api/2/comment/12171/properties/sd.public.comment/"
    def result = curl.execute().text
    output = result.contains("true")

I can use the code above in a condition and it evaluates correctly, but the comment ID is hard coded. I tried this:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager
def id = ComponentManager.getCommentManager().getComments(issue).last().id

to get the comment ID, but I keep getting an error:

No signature of method: static com.atlassian.jira.ComponentManager.getCommentManager() is applicable for argument types: () values: [] Possible solutions: getCommentManager(), getConstantsManager(), getProjectManager(), getVoteManager()

 

How can I get the comment ID in the "Condition" field of Send a custom email?

2 answers

1 accepted

2 votes
Answer accepted
Alejo Villarrubia [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.
July 28, 2015

Can you try with this?

import com.atlassian.jira.component.ComponentAccessor

def id = ComponentAccessor.getCommentManager().getComments(issue).last().id
Chris Knight July 28, 2015

Thanks for the quick reply! Unfortunately, I get this error: No such property: ComponentAccessor for class: Script32

Alejo Villarrubia [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.
July 28, 2015

Sorry I didn't add the import. I've edited my answer.

Alejo Villarrubia [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.
July 28, 2015

Thanks for accepting. Can I ask you to confirm you are testing the script against jira 7 eap?

Chris Knight July 29, 2015

I'm testing it against JIRA 6.3.8.

0 votes
JamieA
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.
July 30, 2015

I really advise you not to use this approach... although kudos for finding it. The problem is that for anyone that uses SSL they are likely to have certificate problems, plus you are hard-coding credentials, and it's not easy to use the credentials of some other user. A better approach (imho) is here: https://answers.atlassian.com/questions/14212548/answers/14212563

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events