Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Add a comment while throwing InvalidInputException


I am trying to validate a JIRA transition using a scriptrunner script. I would want to log some details in the jira comments section and throw a UI exception which says "Refer to comments for more details"


import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager

// some condition evaluation. Lets say one that fails

CommentManager commentManager = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class)
commentManager.create(issue, currentUser,"reason for failure", true)
invalidInputException = new InvalidInputException("Refer to comments for more details")

This code does produce a pop up with

"Refer to comments for more details

It seems that you have tried to perform an illegal workflow operation.

If you think this message is wrong, please contact your JIRA administrators"


The comment does not show up!!!!!! If I do not throw the exception, then the transition will go through and logs a comment.



4 answers


For anyone falling in this same problem, I've found that the comment can be added if you make the change in a new thread.

Just adding:

Thread thread = Thread.start {
try {
def commentManager = ComponentAccessor.getCommentManager()
commentManager.create(issue, user, txt, true)
} catch (Exception e) {
log.error("Thread exception " + e.message + "\n" + e)

It works regardless of validator returning true or false, but it could be better launching the thread only when returning false.


Actual complete code:

import com.atlassian.jira.component.ComponentAccessor;
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.opensymphony.workflow.InvalidInputException

StringBuilder commentBuilder = new StringBuilder()
boolean validationPass = true;

// Logger util to log the workflow
def log = Logger.getLogger("com.acme.CreateSubtask")

// Add comment to JIRA
def createComment = { String value ->
def commentManager = ComponentAccessor.getCommentManager()

def authContext = ComponentAccessor.jiraAuthenticationContext
def user = authContext.getLoggedInUser()

commentManager.create(issue, user, value, true) "Comment has been created"

def networkConnection = {
// x x x x x x some code here

def performValidation = {
HttpURLConnection connection = networkConnection() as HttpURLConnection
try {
if(!connection) {
throw new Exception("blabla")

if(connection.responseCode == 200){
// x x x x x x x some code here
else {
throw new Exception("Error")
} catch (Exception e) {
validationPass = false;
} finally {
invalidInputException = new InvalidInputException(commentBuilder.toString())


Do not throw exceptions like this. Nothing is handling it and your validator code is literally aborting. This is, to put it bluntly, bad. You should never throw exceptions in finally blocks and you really shouldn't let them propagate up to Jira for no reason.

You should return true or return false. So in your case, just create your comment and return false. Otherwise return true.

@Steven, It does not seem to do any good. I thought I was setting the invalidInputException in finally block if validation failed.

Anyways I found out that we have a Simple scripted validator  that expects a true or false from groovy script and stops the transition.

I am making a comment just before the return false statement.

Outcome: It blocks the transition but does not log the comment. Need help!!!!!

I do not think we can ever create a comment if you return false.

Why I say so is, return false will block the transition and you cancel it to close the transition screen acknowledging the error. So kind of rollback.

Am I correct in assuming this? @Steven Behnke

Hi Venkatesh,

Which version of ScriptRunner and JIRA are you running? It seems like you are on an older version. Can you not use the built-in workflow validator feature provided by ScriptRunner? This will allow you to easily display an error message.

Screen Shot 2017-11-27 at 2.39.51 PM.png

Atlassian JIRA

Version : 7.5.3


Scriptrunner (v. 5.2.2)


Joshua Yamdogo @ Adaptavist I have a big validator script and at the end I am able to display all error messages both at the field level and on the screen I linked with my transition,

Question is: I want to log a JIRA comment after the transition has been marked as negative by 



There is a big problem with your current script because you are still using ComponentManager. ComponentManager does not exist in JIRA 7, so any code with it will not work. See our documentation.

import com.atlassian.jira.component.ComponentAccessor

def commentManager = ComponentAccessor.getCommentManager()

commentManager.create(issue,currentUser,"Reason for failure",true)

Perhaps something like this will work to create the comment.

Joshua Yamdogo @ Adaptavist Nope! Nothing logs in comments section despite using the suggestion above.


My Workflow in detail

1. Click on a JIRA state change from "In Progress" to "Advance next"

2. Pop up screen appears as I associated a screen with this transition

3. In the validator script attached with this transition, Do a network API call

  a. if 200 allow transition (then it logs comments on JIRA successfully)

  b. if other like a 401 then block the transition using InvalidInputException.

       User can make a retry and end up in 3.a but if he decides to cancel the transition, he would click "CANCEL" at the end of screen. (HELP!!!!! It won't log the comment :() 

I think your assumption is correct that you won't be able to create the comment if validator returns false and fails to pass.

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events