Forums

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

Get content of a current comment on transition

Roman Blyshchyk March 27, 2019

Hello smart people, 

I am trying to do validation on a comment during a transition between statuses. I want my comment to contain a certain tag, say :

[tagName] <some comment text>

 

If the body of the comment doesn't contain that text - I want to throw a validation message. It seems to me that this has to be done in validation part of the workflow, but I can't figure out how to grab the body of the current comment.  After searching CommentManager, I only found ".getLastComment(issue)", but not currentComment. 

Here is what I have right now:

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger

def commentManager = ComponentAccessor.getCommentManager()
def lastComment = commentManager.getLastComment(issue)
def log = Logger.getLogger("com.acme.workflows")

log.warn(lastComment.body)

if(lastComment.body.contains("[public]")){
return true;
}
else{
return false;
}

 

Thanks,

Roman

1 answer

1 accepted

3 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.
March 27, 2019

You can use transientVars, e.g.

String comment = transientVars?.get("comment")?.toString()

You'll get a Static type checking error in the editor, but it works fine.

jira.jpg

Roman Blyshchyk March 28, 2019

fantastic! thank you, it worked. 

Roman Blyshchyk March 28, 2019

Couldn't find any documentation on transientVars, only a small mention in here:

https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/get-workflow-vars.html

 

Do you know of any documentation on this and other "hidden" things?

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.
March 28, 2019

No, I know of no good source for goodies like that. I just happened to stumble upon transientVars by way of searching for a solution to a problem and also found little in the way of information about it.

Like Roman Blyshchyk likes this
Roman Blyshchyk March 28, 2019

Well, hope things thread brings more searchable info to other users who needs to do the same or similar stuff. 

Thanks for help again :) 

Suggest an answer

Log in or Sign up to answer