Groovy script in post function #2 Add comment to issue via script

In this post I’ll describe a very easy script how to add comment to issue during post function with ScriptRunner.

It would be useful if you will need to calculate values from fields, or add comment to keep any informations in history or in my case, just use it to know what happens and what are real data which are provided (i.e.: Show user permissions, project roles, etc.)

Example use case

We want to add comment, which user does transition of issue and write a short message there and actual user project role information.

// Import all classes which we will need
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager

// Use a static method of ComponentManager to get actual ComponentManager instance. 
ComponentManager componentManager = ComponentManager.getInstance()
// Get a CommentManager instance from component manager
CommentManager commentManager = componentManager.getCommentManager()

commentManager.create(issue, transientVars.context.caller, "Generated comment...", false)

 

Aleš Laňar
Senior Engineer Software ve společnosti CA Technologies

Leave a Reply

Your email address will not be published. Required fields are marked *