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?
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.