You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
hello,
i want to attach pdf attachment(link) in comment using
def commentManager = ComponentAccessor.getCommentManager()
def textComment = fnm + " has been added to the issue"
commentManager.create(issue, currentUser, textComment, null, null, new Date(), true)
above code create comment as "text" not " pdf link",like below
Hi @Sneha Gole
For your requirement, I assume you are using a Listener to trigger the comment update.
You could try something like this:-
import com.atlassian.jira.component.ComponentAccessor
def issue = event.issue
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def attachmentManager = ComponentAccessor.attachmentManager
def commentManager = ComponentAccessor.commentManager
def attachments = attachmentManager.getAttachments(issue)
def latestAttachment = attachments.findAll {
it.filename.endsWith(".pdf")
}.sort { it.created }.last()
def commentBody = "file has been added to the comment"
commentManager.create(issue,loggedInUser, "[^${latestAttachment.filename}] ${commentBody}", false)
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 a few print screens of the tests:-
1) First, when the issue is created, no attachments are added, as shown below.
2) Once an attachment is added, refresh the page, and you will see the comment is automatically added, as shown below.
3) Adding other pdf attachments, and the comment is updated as well as shown below:-
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.
Hi,
@Ram Kumar Aravindakshan _Adaptavist_ comment with lastest attachment is added by every issue update. How to restrict this listener only to add atachment event?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To answer your question, this is not directly possible as there are no existing events that monitor when an Attachment is added.
You will need to create a custom Event for this.
Please refer to this community post for more information.
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.
Hi @Sneha Gole ,
What is the def for variable fnm? Your code tries to append fnm and the string.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hii @Niranjan ,
thanks for quick reply ,
i have pass file path in fnm (/opt/atlassian/jira/temp/EMPLOYEEE.pdf)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Sneha Gole - Should you not be using ComponentAccessor.attachmentManager.createAttachment as you are actually creating an attachment ?
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.
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.
@Sneha Gole i found this discussion
and saw your code .
I am able to attach the file but not to comment but to the issue . Could you help how can we prevent it
Aakanksha
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.