I have two projects: Software and service desk, and wont to copy customer coment from SD to Software. how i can do it with event listeners? all issues have links.
It is my understanding that the issue you want your comment to copy to is linked to the source issue, yes? Also, every single comment should be copied? If that is the case, then the algorithm is pretty easy:
1) Create a custom listener that would trigger on 'Issue commented' event.
2) Write a logic so that only specific issues are processed (i.e. issues from your SD project)
3) Get the body of the last added comment and use it to create a new comment in a linked issue.
Cool... @Ivan Tovbin, where/how do you set up step 3?
Here's what I have so far for the before-mentioned comment event listener idea. It worked in my dev environment last week, but since changing the link type it broke (the comment is copied back to the service desk issue causing a feedback loop). Still fine-tuning. Let me know if you find what I'm missing.
import com.atlassian.jira.event.issue.IssueEventimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.ComponentAccessorimport com.atlassian.jira.issue.comments.Commentimport com.atlassian.jira.issue.comments.CommentManagerimport com.atlassian.jira.issue.link.IssueLinkManagerimport com.atlassian.jira.issue.link.IssueLinkimport com.atlassian.jira.user.ApplicationUserimport org.ofbiz.core.entity.GenericValueimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.Issue;def issueLinkManager = ComponentAccessor.getIssueLinkManager()def commentManager = ComponentAccessor.getCommentManager()def issue = event.issue as MutableIssue// gather the original author and comment body from the original issues commentdef lastcomment = event.getComment()String lclc = lastcomment.getBody().toLowerCase()def commentBody = lastcomment.getBody()def commentAuthor = lastcomment.getAuthorApplicationUser()// get original issue linked issuesissueLinkManager.getInwardLinks(issue.getId()).each {issueLink ->; if (issueLink.issueLinkType.name == "Service Desk") { //if the last comment author is not your automation account (if you have an account that responds to the customer on other listeners) then if(lastcomment && !(commentAuthor.getDisplayName().equals("AutomationAccount"))) { // create comment on the linked issue and fire the comment event on that issue def modCommentBody = "*{color:#3b7fc4}FROM SERVICE DESK (DO NOT REPLY HERE):{color}*\n" + commentBody commentManager.create(issueLink.getSourceObject(), commentAuthor.getName(), modCommentBody , true) } }}
Found my problem - change getDestinationObject() to getSourceObject(). So you'll need to check the link type direction for your setup. If you use Outward, use Destination; if you use Inward, use Source. Previous comment corrected.
@Brian Alden
I have 2 projects (one SD e the outher Software)
SD = Project ASoft = Project B
I have managed through your script to copy the comments made in project A to project B.
I'm having a hard time doing the reverse, copying from Project B to Project A
In my theory, it would just change the project the listener is checking, but nothing happens ..Would you help me?
@Dante Labate
When you make the reverse listener, you need to flip 'getSourceObject()' to 'getDestinationObject()' - this is in reference to the issue link direction.
Another thing to keep in mind is that the comment author must have comment permission in the project you are copying to, in this case your SD project. And if the user commenting in the software project doesn't have an Agent license, their comment will be made on the SD project as an internal comment (not visible to the portal).
Good luck!
Can script runner copy comments from linked issues, across different projects?
Yes, as long as those projects are within a single Jira instance. If not you'll have to use REST API to access issues from another Jira.
That's grand, thank you.
We are using the Jira cloud hosted solution, is that going to cause us an issue achieving this?
It looks like you're new here. Sign in or register to get started.