Forums

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

Problem with behaviors' on entry validation

Paul December 4, 2018

Hi all,

I need to validate format for "My Example Field" during issue creation by a user.

User entry should consists of prefix (always "ABCD") and suffix (a number), e.g. ABCD12345.

The code below, obviously, doesn't work.

Problems:

1. If a user enter any string less than 9 characters, no validation happens; it has to be 9 or more.

2. Doesn't matter what a user enter for a prefix - no validation of prefix at all.

3. For string equal or more than 9 characters, only suffix is validated (characters from 5 to 9).

 

Code:

import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.opensymphony.workflow.InvalidInputException

String field = getFieldByName("My Example Field").getValue()

String prefix = field.substring(0, 4);
String suffix = field.substring(4, 9);

if (!prefix == "ABCD"){
getFieldByName("My Example Field").setError("Incorrect prefix: " + prefix)
}
else if (!suffix.isInteger()){
getFieldByName("My Example Field").setError("Incorrect suffix: " + suffix)
}
else {
getFieldByName("My Example Field").clearError()
}

 

Any ideas please?

 

1 answer

0 votes
Paul December 17, 2018

Bump.

It seems as an easy task but it looks like string format validation doesn't work in ScriptRunner?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events