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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

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
4,551,681
Community Members
 
Community Events
184
Community Groups

How to throw two errors on two different fields using custom script validator

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

 

3 answers

1 accepted

1 vote
Answer accepted
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 05, 2019

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

1 vote
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 05, 2019

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.

Hello @Peter-Dave 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.

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 05, 2019

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.

Hi @Antoine Berry ,

Thank you. That works. 

Best Regards,

Swapnil Srivastav.

Like Antoine Berry likes this

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

Like Antoine Berry likes this

Hi Antoine,

Can you help me on the above query...

 

Regards,

Queenmary Bastin

Like Antoine Berry likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events