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:
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}}
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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry I didn't add the import. I've edited my answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for accepting. Can I ask you to confirm you are testing the script against jira 7 eap?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.