Internationalize "error message" form field from Simple Scripted Validator (Script Runner)

FRANCISCO JOSE ARROYO CASTRO September 14, 2016

Hi.
I am using Script Runner for validating a lot of custom fields.
Now I have to translate the error messages.

 

scripted_yellow.png

I am unable to show a message depending on the user's language setting. I've tried to use a language key (from a custom plugin), i18nHelper.getText(), with no success

¿Is it possible to internationalize this form field?

 

Thank you!!

 

 

1 answer

0 votes
Jonny Carter
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.
September 14, 2016

You won't be able to provide a dynamic language like that with the Simple Scripted Validator, but you might be able to pull it off with a regular Scripted Validator.

Just change the string text in the exception you throw to match the user's language setting.

To get your other plugin's i18nHelper object, you may want to read up on scripting other plugins as well.

FRANCISCO JOSE ARROYO CASTRO September 16, 2016

Thank you for your response.


I've tried replacing "Simple Scripted Validator" with "Custom Script Validator" but now I'm facing another issues.

When validation fails and I throw a InvalidInputException("fieldname", "error"), JIRA places the error message at the top of the dialog instead of the field's bottom. However when I use a Simple Scripted validator, JIRA places it correctly. ¿How can I show the error message at the bottom of the associate custom field?

  

error_at_top.jpg

 

Another difference when I use "Custom Script Validator" is that JIRA adds a header before the list of errors ("There were some errors when trying to create this issue"). Using Simple Scripted Validator only shows the message without any header. I'd like to show the error message without any header, but It is not important.

Thank you

Jonny Carter
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.
September 16, 2016

Pass the field name to the exception constructor as an argument. From the docs:

throw new InvalidInputException("myField", "UR DOIN IT RONG")

The general messages are those without a field parameter specified:

throw new InvalidInputException("UR DOIN IT RONG IN A MOAR GENERAL WHEY")
FRANCISCO JOSE ARROYO CASTRO September 18, 2016

Hi Again

Maybe I've explained bad, English is not my main language.

I'll try to explain with other words wink

 

I am already doing that.

throw new InvalidInputException(fieldName,errorMessage);

where fieldName is the custom field name that appears on /secure/admin/ViewCustomFields.jspa list. I have tried the translation name too.

The only way is using customfield_10029 that It is the id of the field in the form on the screen.I don't like using the id because we have multiple environments where we replicate the configuration, but the id of the fields does not have to be the same

 

 

Suggest an answer

Log in or Sign up to answer