Forums

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

Adding lines breaks to Scriptrunner Custom script validator InvalidInputException

Davin Studer
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.
February 14, 2018

I've got a Custom script validator that is testing multiple fields prior to transitioning the issue. If a field fails validation I append error text to a string that I throw as a InvalidInputException if the string is not empty. However, the error that the users sees does not have line breaks. All the error messages are just lumped together. Is there a way to do this, or maybe I'm just doing this wrong? Thanks.

def errorText = "";

if(a != b) {
errorText += 'A did not equal B.\n';
}

if(C != D) {
errorText += 'D did not equal C.\n';
}

if (errorText != "") {
throw new InvalidInputException(errorText)
}

 

2 answers

1 vote
Tim Chen November 10, 2021

I found the api: https://javadoc.io/doc/com.trunkplatform.opensymphony/osworkflow/latest/com/opensymphony/workflow/InvalidInputException.html 

And the following sample code is worked for me

invalidInputException = new InvalidInputException('1st error message.')
invalidInputException.addError '2nd error message.'
invalidInputException.addError 'Other messages.'
return invalidInputException

I'm using Jira 8.13.1 and ScriptRunner 6.14.0

0 votes
Davin Studer
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.
February 14, 2018

This isn't pretty, but this how I've gotten around it for now. I'm open to better solutions.

I added this to the system level announcement banner.

<style type="text/css">
div[id^="workflow-transition-"] .aui-message.error p:nth-of-type(1) {white-space: pre;}
</stye>

Suggest an answer

Log in or Sign up to answer