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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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!

0 votes
Ivan Tovbin Community Leader Jan 06, 2018

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?

Can script runner copy comments from linked issues, across different projects?

Ivan Tovbin Community Leader Jun 06, 2019

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?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Asked in Jira Service Desk

Calling all Insight users, we need your help!

Hello Insight users,  As part of our (Mindville's) acquisition by Atlassian, our training team is looking to build some new Insight training materials. It would really helpful if you can ...

97 views 1 0
View question

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you