Can I use Script Runner's Clone Issue to copy comments?

Gabriel August 20, 2015

This seems like something I should be able to supplement within the configuration of Script Runner's clone issue template.  I'm sure if I had the correct code to execute as an additional issue function, I could implement it.  I'm just not knowledgable to come up with it myself, yet.  Any help from those smarter than myself is greatly appreciated! 

2 answers

0 votes
Hung Nguyen January 21, 2016

Jamie,

I tried this approach with the following script in the post function:

 

import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor

CommentManager commentMgr = ComponentAccessor.getCommentManager();
Collection<Comment> comments = commentMgr.getComments(sourceIssue);
for (Comment comment : comments) {
    commentMgr.create(issue, comment.getAuthorApplicationUser(), comment.getBody(), false);
}

 

But I always got

[scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: ..., file: null

java.lang.NullPointerException

    at com.atlassian.jira.issue.comments.DefaultCommentManager.create(DefaultCommentManager.java:258)

 

Any advice on this?

Thanks

hung

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 22, 2015

Have a look at https://docs.atlassian.com/jira/6.4.3/com/atlassian/jira/issue/comments/CommentManager.html. You would iterate the comments on the source issue, and create corresponding comments on the target issue.

Suggest an answer

Log in or Sign up to answer