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

sbhutada 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

1 vote
Bart_Joosten 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-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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
0 votes
Nic Brough -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.
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