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.
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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are welcome, Jackson.
Have a nice weekend!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Note that the script on that page will work just the same in a JMWE Scripted (Groovy) Validator.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.