Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to update latest comment from an issue using Scriptrunner

Xavier
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 23, 2022

Hi all,

 

in a Jira workflow, I add a transition (available on customer portal). Then, when user click on transition link, a default window appears, with possibility to add a comment.

In the workflow post function, i'would like to update this comment by adding a specific text.

how I can proceed ?

I can correctly retrieve the lastcomment, but xxx.update(mylastcommentid, "add the text", false) didn't work, or delete and then re-adding a comment not working anymore.

 

Is there a simple way to update latest comment?

thanks in advance.

 

1 answer

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 25, 2022

Hi @Xavier

For your requirement, you could try something like this:-

import com.atlassian.jira.component.ComponentAccessor

def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def commentManager = ComponentAccessor.commentManager

def lastComment = commentManager.getLastComment(issue)

def updateComment = """${lastComment.body}
sample update
""".toString()
commentManager.delete(lastComment)
commentManager.create(issue, loggedInUser, updateComment, false)

Please note the sample working code above is not 100% exact to your environment. Hence, you will need to modify it.

What this code does is that whenever it transitions to a specific status, for example, from To Do to In Progress, it will copy the original value from the last comment and copy the value of the last comment to another String which will also append another line of text to it. It will then remove the last comment and replace it with the updated String.

Below are a few print screens for your reference:-

1. First, an issue is created, and a comment is added to it. It is still in the To Do status.

image1.png

2. Once the issue transitions to the In Progress status, the last comment is updated with the additional text as shown below:-

image2.png

I hope this helps to solve your question. :)

Thank you and Kind regards,

Ram

 

Xavier
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 27, 2022

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

thank you for your quick feedback.
this not working on our side (from customer portal, the window with comment insertion is displaying a long time, and the unknow error message appear. Nothing in log..)

I will try to debug what happens.
But really appreciate the help.
regards

Suggest an answer

Log in or Sign up to answer