A couple of transitions in our Service Desk workflow are internal in nature, so a comment provided during the transition should be an internal comment. I would like to create a validator to make sure that is the type chosen, but I am coming up empty. I have found references to determining whether existing comments are internal, but in my case, the comment does not yet exist.
An example of determining whether an existing comment is internal:
def isInternal = { Comment c ->
def commentProperty = commentPropertyService.getProperty(user, c.id, SD_PUBLIC_COMMENT).getEntityProperty().getOrNull()
if (commentProperty) {
def props = new JsonSlurper().parseText(commentProperty.getValue())
props['internal']
}
else {
true
}
}
Thanks!
Payne
I have devised the following solution - I created a ScriptRunner scripted validator as follows:
import groovy.json.JsonSlurper
import groovy.json.JsonParserType
def returnValue = true
def commentProperty = transientVars?.get("commentProperty")?.toString()
//commentProperty will look like this: [[{key: "sd.public.comment", value: {internal: "true"}}]]
if (commentProperty != null) {
//strip the leading [[ and trailing ]] from the string
commentProperty = commentProperty.substring(2,commentProperty.length()-2)
//set Type to LAX to compensate for the fact that not all of the strings are surrounded by quotes
def props = new JsonSlurper().setType(JsonParserType.LAX).parseText(commentProperty)
returnValue = props.key == "sd.public.comment" && props.value["internal"] == "true"
}
else {
returnValue = true
}
return returnValue
with an error message of "The comment should be an Internal Comment."
Cheers,
Payne
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.