Forums

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

Jira service Desk external comments in script runner

Abdulrahman Aldakak February 11, 2020

Hello,

i have the following problem,

i am trying to create a scripted Custom filed that do the following : the script field should shows true if the issue include  a external comment and false if the issue doesn't  include an external comment and it works but  the problem is, when an old issue that includes very old external comments the script field doesn't show that the issue includes external comment

this is the script that i am using: 

//comment id
final SD_PUBLIC_COMMENT = "sd.public.comment"

def commentManager = ComponentAccessor.commentManager
def commentPropertyService = ComponentAccessor.getComponent(CommentPropertyService)

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

// get whether the comment is internal or not, null means no property found, maybe not an SD issue
def isInternal = { Comment comment ->
def commentProperty = commentPropertyService.getProperty(user, comment.id, SD_PUBLIC_COMMENT)
.getEntityProperty().getOrNull()

if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.getValue())
props['internal']
}
else {
null

}
}



// Example:all external comments on issue
//def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("PROJ-1");
//log.debug commentManager.getComments(issue).findAll { !isInternal(it) }
if (commentManager.getComments(issue).findAll { ! isInternal(it) })
return "true"
else {
return "false"
}

 Thanks

1 answer

1 accepted

0 votes
Answer accepted
Payne
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.
February 11, 2020

I do something similar, and one difference that I note that may help you is that I set the type to LAX when defining the props object; the reason is that some, but not all, of the strings included in the JSON object are surrounded by quotes. I define props this way:

def props = new JsonSlurper().setType(JsonParserType.LAX).parseText(commentProperty.getValue())

Worth trying; it may solve your problem.

Abdulrahman Aldakak February 11, 2020

Thanks i am going to try it

Suggest an answer

Log in or Sign up to answer