import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
String issueKey = "IP-123456"
def commentIDs = ["1234567", "1234689"]
commentIDs.eachWithIndex{ item, index ->
int commentID = Integer.parseInt(item);
IssueManager issueManager = ComponentAccessor.issueManager
CommentManager commentManager = ComponentAccessor.commentManager
MutableIssue issue = issueManager.getIssueObject(issueKey)
List<Comment> comments = commentManager.getComments(issue)
comments.each {comment ->
if (comment.id == commentID) {
commentManager.update(comment, false)
}
}
}
Hey :)
What exactly are you trying to do? The code provided doesn't actually modify the comment body, it just updates the comment with its current content.
Are you on a recent version of ScriptRunner? If you are running ScriptRunner 8.3.0 or later you could use HAPI to simplify this kind of task.
For example with HAPI a script to update specific comment bodies would look something like:
Issues.getByKey('SR-100').comments.each { comment ->
if (comment.id in [10001L, 20003L]) {
comment.update {
body = 'New comment body'
dispatchEvent = false
}
}
}
If you are using an older version of ScriptRunner, you would need to cast the comment to MutableComment, update the body, and then call commentManager.update
Cheers
Thank you for your detailed answer; i just need the second option with MutableComment and commentManager.update and your advice gave me a first working solution. Because iam completely new to Scriptrunner/Groovy i actually dont know all methods and commands.
But if i add the line comment.setBody("new body") you indirectly mentioned its working. Thank you :D
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
String issueKey = "IP-123456"
def commentIDs = ["1234567", "1234689"]
commentIDs.eachWithIndex{ item, index ->
int commentID = Integer.parseInt(item);
IssueManager issueManager = ComponentAccessor.issueManager
CommentManager commentManager = ComponentAccessor.commentManager
MutableIssue issue = issueManager.getIssueObject(issueKey)
List<Comment> comments = commentManager.getComments(issue)
comments.each {comment ->
if (comment.id == commentID) {
comment.setBody("new body")
commentManager.update(comment, false)
}
}
}
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.