You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hello!
I'm trying to add a Script Post-Function [ScriptRunner] which will clone all the comments from the current issue to the linked issue (with the specific link type).
I'm not good in groovy, so I found a couple of examples, changed and merged them into one script, which I suppose should do what I need.
There is no errors displayed when I open the script in the post-function editor, it also says that there is no failures in the all executions, but the comments are not cloned to the linked issue.
Please, help to understand why this script does not clone the comments from the current issue to the linked issue.
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.plugin.webfragment.model.JiraHelper;
IssueManager issueManager = ComponentAccessor.getIssueManager();
CommentManager commentMgr = ComponentAccessor.getCommentManager();
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
JiraHelper jiraHelper = new JiraHelper();
Issue currIssue = (Issue) jiraHelper.getContextParams().get("issue");
issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->;
def linkedIssue = issueLink.destinationObject
String issueType = issueLink.destinationObject.getIssueType().toString()
if (issueLink.issueLinkType.name == "Implementation" ) {
Collection<Comment> comments = commentMgr.getComments(currIssue);
for (Comment comment : comments) {
String groupLevel = comment.getGroupLevel();
Long roleLevelId = comment.getRoleLevelId();
Date created = comment.getCreated();
Date updated = comment.getUpdated();
ApplicationUser author = comment.getAuthorApplicationUser();
ApplicationUser updateAuthor = comment.getUpdateAuthorApplicationUser();
commentMgr.create(linkedIssue, author, updateAuthor, comment.getBody(),groupLevel, roleLevelId, created, updated, false, false);
}
}
}
I found a problem in the script, the problem was that I tried to use a variable
Issue currIssue = (Issue) jiraHelper.getContextParams().get("issue");
for accessing the current issue.
here is the script that works for me:
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.plugin.webfragment.model.JiraHelper;
IssueManager issueManager = ComponentAccessor.getIssueManager();
CommentManager commentMgr = ComponentAccessor.getCommentManager();
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->;
def linkedIssue = issueLink.destinationObject
String issueType = issueLink.destinationObject.getIssueType().toString()
Collection<Comment> comments = commentMgr.getComments(linkedIssue);
if (issueLink.issueLinkType.name == "Implementation" ) {
for (Comment comment : comments) {
String groupLevel = comment.getGroupLevel();
Long roleLevelId = comment.getRoleLevelId();
Date created = comment.getCreated();
Date updated = comment.getUpdated();
ApplicationUser author = comment.getAuthorApplicationUser();
ApplicationUser updateAuthor = comment.getUpdateAuthorApplicationUser();
commentMgr.create(issue, author, updateAuthor, comment.getBody(),groupLevel, roleLevelId, created, updated, false, false);
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.