Hi there! with my script I want to replicate the comment entered in the destination issue when I generating a link
The code gives me an error in the following script line:
def lastcomment =event.getComment()
No signature of method: java.lang.String.getComment() is applicable for argument types: () values: []
I leave the complete code:
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent
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.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.event.issue.IssueEvent
def log = Logger.getLogger("com.nolddor")
log.setLevel(Level.DEBUG)
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def commentManager = ComponentAccessor.getCommentManager()
def event = event as IssueLinkCreatedEvent
def issueLink = event.issueLink
def sourceIssue = event.issueLink.sourceObject
def destinationIssue = event.issueLink.destinationObject
def lastcomment =event.getComment()
def comments = ComponentAccessor.commentManager.getComments(sourceIssue)
String lclc = comments.body.last()
log.debug(lclc)
//def commentAuthor = comments.getAuthorApplicationUser()
if (comments) {
//commentManager.create(destinationIssue, loggedInUser, "sdf", true)
def autor= comments.last().getAuthorApplicationUser()
log.warn(autor)
//commentManager.addCommentToObject()
//commentManager.create(destinationIssue, comments.authorApplicationUser, comments.body, true);
commentManager.create(issueLink.getDestinationObject(), autor, lclc, true)
}
log.debug "An IssueLinkCreate event has been catched"
log.debug "Issue (from): ${sourceIssue.key}"
log.debug "Issue (to): ${destinationIssue.key}"
Hi @Ignacio Flores,
You are encountering the error because there is no getComment() method in the bound variable event.
Instead, it would be best if you used the Comment Manager to get the Comment, i.e.:-
def commentManager = ComponentAccessor.commentManager
.
.
.
def comments = commentManager.getComments(sourceIssue)
If you intend to pass the latest comment from the Source Issue to the Destination Issue, you can try this working code:-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def commentManager = ComponentAccessor.commentManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueLink = event.issueLink
def destinationIssue = issueLink.destinationObject as MutableIssue
def sourceIssue = issueLink.sourceObject as MutableIssue
def comments = commentManager.getComments(sourceIssue)
def latestComment = comments.last()
commentManager.create(destinationIssue, loggedInUser, latestComment.body, true)
Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a print screen of the Listener configuration:-
Below are some print screens of the test:-
1) The destination issue before it is linked to the source issue:-
2) The source issue, with the comments:-
3) The destination issue after it is linked to the source issue with only the latest comment from the source issue:-
I hope this helps to solve your question. :)
Thank you and Kind Regards,
Ram
@Ram Kumar Aravindakshan _Adaptavist_
Hi there! Thank you very much for your prompt reply friend. Indeed, what you show me I can do, but what I need is that at the moment I am creating the link, at that very moment I am going to add a comment, that comment is the one that I want to be transferred to the destination issue. Not the last comment before creating the link, but the comment entered when generating the link. Excuse me if I don't explain it well
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you please specify which issue link type do you want to copy the latest comment from?
For example, from the outward link (blocks) to the inward link (is blocked by)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi @Ram Kumar Aravindakshan _Adaptavist_
From the outward link (Aprueba) to the inward link (Aprobado por)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What you are trying to achieve cannot be performed because the comment that is added in the dialog box when creating the outward link, i.e.:-
is not committed to the Database at the time the event is fired.
The alternate approach I would suggest is first to add a comment in the comment area, i.e.:-
and then link your issue. By making this approach, you can be sure that the Listener will be able to take the last comment and add it to the linked issue.
I hope this helps to solve your question. :)
Thank you and Kind Regards,
Ram
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.
Hi @Ignacio Flores,
Great!. Since the suggested solution works for you, please accept the answer.
Thank you and Kind Regards,
Ram
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.