Forums

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

Is there a way to limit Service Desk comments on a transition to Internal?

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.
August 30, 2018

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

1 answer

1 accepted

1 vote
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.
September 10, 2018

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

Suggest an answer

Log in or Sign up to answer