how to update a comment inside of jira with Plugin?

Hi,

I need to update a comment,

I can get the comment id and author.

Just need to update the comment body with plugin.

Which class should i use?

I have tried CommentManager.Update().

But i can not find how to update the comment body.

void update(Comment comment,
            boolean dispatchEvent)
Persists the updated comment.
Parameters:
comment - to update
dispatchEvent - if true then an event of type EventType.ISSUE_COMMENT_EDITED_ID will be dispatched and any notifications listening for that event will be triggered. If false no event will be dispatched.
Throws:
IllegalArgumentException - if comment passed in is null or its id is null

1 answer

1 accepted

I have had a look in the JIRA sources and you need to get a MutableComment in the first place. Note that getCommentById returns a Comment, but under the hood, there is actually a MutableComment). You can setBody with this interface. The rest is simple, as you have already found out the update method in CommentManager.

Thanks so much,

I will try it.

HI Silviu,

I can see the mutableComment description says:

Represents a comment's in JIRA. After calling any 'setter' method, you will need to call CommentService.update(com.atlassian.jira.user.ApplicationUser, com.atlassian.jira.issue.comments.MutableComment, boolean, com.atlassian.jira.util.ErrorCollection) which does permission checking or CommentManager.update(com.atlassian.jira.issue.comments.Comment, boolean) which will just store the provided object, to persist the change to the database.

https://docs.atlassian.com/jira/6.1.5/com/atlassian/jira/issue/comments/MutableComment.html

Should i use commentService or CommentManager to update comment?

What the different between them?

If i want to use CommentService to update the comment, how to get the ErrorCollection instance?

Hi,

CommentService uses CommentManager under the hood. If you want, you can use CommentService to also check for permissions, but I think you will only need CommentManager.
As for ErrorCollection, here is how JIRA does:

SimpleErrorCollection errorCollection = new SimpleErrorCollection();

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,181 views 13 19
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot