import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.comments.Commentimport com.atlassian.jira.issue.comments.CommentManagerString issueKey = "IP-123456"def commentIDs = ["1234567", "1234689"]commentIDs.eachWithIndex{ item, index -> int commentID = Integer.parseInt(item);IssueManager issueManager = ComponentAccessor.issueManagerCommentManager commentManager = ComponentAccessor.commentManagerMutableIssue 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 } }}
HAPI - Work with Comments
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
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.issue.comments.Commentimport com.atlassian.jira.issue.comments.CommentManagerString issueKey = "IP-123456"def commentIDs = ["1234567", "1234689"]commentIDs.eachWithIndex{ item, index -> int commentID = Integer.parseInt(item);IssueManager issueManager = ComponentAccessor.issueManagerCommentManager commentManager = ComponentAccessor.commentManagerMutableIssue 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) }}}
It looks like you're new here. Sign in or register to get started.