Accessing Comment ID in Custom Email Condition via ScriptRunner

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

Can you try with this?

import com.atlassian.jira.component.ComponentAccessor

def id = ComponentAccessor.getCommentManager().getComments(issue).last().id

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

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

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

I'm testing it against JIRA 6.3.8.

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
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,372 views 0 8
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