Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,458,307
Community Members
 
Community Events
176
Community Groups

Copy comment to linked issue with event listeners

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.

3 answers

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.

@Brian Alden 

 

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?

@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!

@Brian Alden 

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!

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?

0 votes

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?

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events