Forums

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

How to Check comment is Public in Validator

Jackson Farnsworth
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.
October 4, 2018

I've seen multiple posts on how to get the comment string, but I need the comment object, or at least the comment ID to check the properties of a comment. Currently using 'Scripted (Groovy) Validator (JMWE add-on)' to create the script. Could also use Scriptrunner add-ons 
Point of this validator being to check if the comment is Internal or Public.

2 answers

1 accepted

1 vote
Answer accepted
Petter Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 4, 2018

Hello Jackson,

Actually, you can find the comment using the comment String itself to check the visibility of the comment.

Please, check the instructions provided in topic Scripting Service Desk > From a workflow function from the documentation below:

https://scriptrunner.adaptavist.com/latest/jira/recipes/misc/jira-service-desk.html

Jackson Farnsworth
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.
October 5, 2018

I've used the code from that link, and added in some logging tools to check it. No matter the return value, the validator lets the comment though. (Using the Scriptrunner custom validator now)

Here's what I'm using:

import groovy.json.JsonParserType
import groovy.json.JsonSlurper
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.INFO)

def commentProperties = transientVars["commentProperty"] as String[]

def isInternalComment = false

if (commentProperties) {
def commentProperty = commentProperties.first()
def props = new JsonSlurper().setType(JsonParserType.LAX).parseText(commentProperty)

isInternalComment = props.find {it.key == "sd.public.comment"}?.get("value")?.get("internal")
}

log.info "Should Succeed?: ${!(isInternalComment.toBoolean())}"
return !(isInternalComment.toBoolean())

 

Is there something I'm missing for creating a validator? 

David Fischer
Community Champion
October 5, 2018

I just tried it as a Scripted (Groovy) Validator (JMWE add-on) on the "Respond to Customer" transition of a SD workflow, and it throws an error if the comment is internal.

Jackson Farnsworth
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.
October 5, 2018

Weird, it doesn't work with Scriptrunner, but works fine with the JMWE plugin. 
All good now though. Thanks everyone!

For those interested...
Scriptrunner Version:
5.4.28

Petter Gonçalves
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 5, 2018

You are welcome, Jackson.

Have a nice weekend!

0 votes
David Fischer
Community Champion
October 4, 2018

Note that the script on that page will work just the same in a JMWE Scripted (Groovy) Validator.

Suggest an answer

Log in or Sign up to answer