Extract content of deleted comment after ISSUE COMMENT DELETED event in scriptrunner listener

sbhutada
Contributor
January 11, 2019

I have set up an ISSUE COMMENT DELETED event in scriptrunner listener. Every time when a user deletes the comment I have to update the backend system to delete the same comment.

Is there any way in scriptrunner listener to find out the comment body of deleted comment?

2 answers

2 votes
Bart_Joosten
Contributor
January 14, 2020

@sbhutada @Nic Brough -Adaptavist- 

Sorry but i need to correct Nic Brough on this one, the event does have information about the action you where executing. To get the old comment information u can use the following code:

import org.apache.log4j.Level
import org.apache.log4j.Logger
Logger log = Logger.getLogger("runner.ScriptRunnerImpl")
log.setLevel(Level.DEBUG)
log.setAdditivity(false)

Comment comment = event.params["originalcomment"]

log.info("Whats my id: " + comment.id)
log.info("Whats my body: " + comment.body)
 

It is not stored inside the comment but you are able to find it back in the event params as originalcomment.  It is also always good to print the full event then you can see what information the event contains:

log.info("What is my event: "+ event)


Hope this helps other people to :), good luck everyone happy programming!

Nic Brough -Adaptavist-
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.
January 14, 2020

No need to apologise for correcting this!  It used to be the case that issue delete had nothing, but it does now.

Like Bart_Joosten likes this
alfafire October 3, 2024

Hello @Bart_Joosten , thanks a lot for your solution. That's great! I used it in ScriptRunner Listener to send email notification for comment added/updated/deleted cases.

0 votes
Nic Brough -Adaptavist-
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.
January 11, 2019

No, the event only holds the information about the event, not what the event was acting on.

You've deleted the comment.  By the time the listener picks up the event, the data has gone.

I'd recommend the users of your "backend" system use Jira for the source of the data, rather than duplicate (and hence lose or obsolete) data.

Suggest an answer

Log in or Sign up to answer