The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Scriptrunner, a script listener to log all external comment

Jason Li Ting Chung
Contributor
February 2, 2021

Hi community,

I have a script which is supposed to create a log of all external comments during an event listener.

Here is my code:

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.comments.CommentManager

import com.atlassian.jira.issue.comments.Comment

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.event.issue.IssueEvent

import groovy.json.JsonSlurper

import com.onresolve.scriptrunner.runner.customisers.PluginModule

import com.onresolve.scriptrunner.runner.customisers.WithPlugin

import com.atlassian.servicedesk.api.comment.ServiceDeskCommentService

import org.apache.log4j.Logger

import org.apache.log4j.Level

import com.atlassian.jira.bc.issue.comment.property.CommentPropertyService

 

@WithPlugin('com.atlassian.servicedesk')

 

@PluginModule

ServiceDeskCommentService serviceDeskCommentService

 

final SD_PUBLIC_COMMENT = "sd.public.comment"

 

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)

 

def commentManager = ComponentAccessor.getCommentManager()

def event = event as IssueEvent

def issueManager = ComponentAccessor.issueManager

def issue = event.getIssue()

def comment = event.getComment()

 

def isInternal = { Comment c ->

                def commentProperty = commentPropertyService.getProperty(user, c.id, SD_PUBLIC_COMMENT).getEntityProperty().getOrNull()

}

 

commentManager.getComments(issue).each {

    if (isInternal(it) == false){

        def log = Logger.getLogger("Comments")

        log.setLevel(Level.DEBUG)

 

        log.debug it.body

   }

}

 

The problem is that no log is being created even if the script work without error.

Is there a problem with the script?

 

Best regards,

Jason Li

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Daniel Ebers
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 Champions.
February 3, 2021

Hi @Kristin Lyons

do I understand you basically right that it would suffice to have the whole history of external comments listed in a reply that goes out to the customer BUT not only the last one?

If this is understood correctly voting for the following Suggestions might be a good idea to show it is of interest to your team:

https://jira.atlassian.com/browse/JSDSERVER-5228

Regards,
Daniel

0 votes
Kristin Lyons
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 Champions.
February 2, 2021

I don't have an answer for you but I'm curious what the use case is for this.

Jason Li Ting Chung
Contributor
February 2, 2021

Hi Kristin Lyons,

First of all, I excuse myself for wrong wording I used. I mean external comment rather than internal.

Second, the case scenario is that our client do not want to use portal and use email request only. In this situation, they need to provide their customer of all external comments which the latter create.

Unfortunately, JSM only provide the last external comment of the ticket when replying by email and this is an issue for our client.

Hope this clarified the case.

Best regards

Kristin Lyons
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 Champions.
February 2, 2021

Thanks for the use case.  Is there a specific reason why the client does not want to use the portal?  Sorry that this is not answering your question directly but maybe we can figure out another way to get this to work.

TAGS
AUG Leaders

Atlassian Community Events