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.
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.IssueEvent
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.ComponentAccessor
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.user.ApplicationUser
import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.component.ComponentAccessor
import 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 comment
def lastcomment = event.getComment()
String lclc = lastcomment.getBody().toLowerCase()
def commentBody = lastcomment.getBody()
def commentAuthor = lastcomment.getAuthorApplicationUser()
// get original issue linked issues
issueLinkManager.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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have 2 projects (one SD e the outher Software)
SD = Project A
Soft = 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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you!
I was able to create the reverse.
In the Project SD listener for Project Soft I had to use if to check if the last comment was from my jirabot user.
In the Project Soft listener for Project SD, I removed this check.
Now it's working perfectly!
again, thank you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Brian Alden apologies to bring up an old thread but I don't suppose you have a copy of your script to use in Jira Cloud? Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can script runner copy comments from linked issues, across different projects?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's grand, thank you.
We are using the Jira cloud hosted solution, is that going to cause us an issue achieving this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.