I want to validate two different fields in a Custom Script Validator and show two different errors on the fields if both the validations fail.
Currently it is showing only one error, the one I have mentioned in the last
Any help would be appreciated
Hi @SWAPNIL SRIVASTAV ,
You can throw an error on a field within a validator script using :
throw new InvalidInputException("customfield_11001","This field is mandatory.")
Then you need to make use of if conditions to check if both fields fail validation.
Antoine
The "throw new InvalidInputException" will interrupt the code so you can only throw one.
So either throw it without specifying the field (and then the error message will be at the top of the form), or you duplicate your code and have 2 separate validators. You can still look at the values for both fields to determine which message to display, but you'll have to point one configuration to show the message on one field and the other configuration for the other field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @PD Sheehan and @Antoine Berry ,
Thank you for the responses.
throw new InvalidInputException("customfield_11001","This field is mandatory.")
This worked for me. I applied two if conditions for checking two fields in a single validator and each if block had one throw statement. It is showing error on screen properly.
The only problem is that if both validation fail, it will show the first error first and if you enter the correct value there, then the error of the second field will be shown. It wont show both errors at the same time. Is there any way to do that?
Thanks and Regards,
Swapnil Srivastav.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @SWAPNIL SRIVASTAV ,
You should add a validator on each field checking for both field values, i.e. something like
if (value1 == null && value2 != null) {
throw new InvalidInputException("customfield_11001","This field is mandatory.")
}
else if (value1 == null && value2 == null) {
throw new InvalidInputException("customfield_11001","This field and field 2 are mandatory.")
}
And have something similar on field 2.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Swapnil,
I am also in the same need to display two error message at a same time in the jira screen.
If that works good for you can you please provide the code snippet below that will be a great help for me.
Regards,
Queenmary Bastin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.