How to validate a custom field with Script Runner

Roberto Saltini October 1, 2016

Hi,

I am aware that it is possible to validate a custom field during a transition by means of a custom validator.

However, I could not find any way to validate the value of a custom field every time that its value is changed.

Is writing my own plugin the only solution?

Thanks.

3 answers

0 votes
JamieA
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.
October 3, 2016

Apart from the info in the two other good answers, my answer would be Yes.

Implement com.atlassian.jira.issue.customfields.CustomFieldType#validateFromParams, but it's not as useful as it could be, as you just get the raw string values.

I think what you are referring to is often known as "edit validators" - it exists in a few plugins. Implementations tend to rely on monkey-patching IssueService, which we are avoiding.

Steven F Behnke
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.
October 3, 2016

Sorry to bug you, do you happen to know how the Resolution field is validated? I was under the impression the 'field requirement' is built into the field template – Implying there's no server-side validation.

Have a good day!

JamieA
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.
October 3, 2016

com.atlassian.jira.issue.fields.ResolutionSystemField#validateParams - system fields a bit different. 

Steven F Behnke
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.
October 3, 2016

Thanks!

0 votes
Steven F Behnke
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.
October 2, 2016

As Nic implies this is happening because you are allowing users to directly edit field values. There's no out-of-the-box way to validate input other than simply 'requiring' the field via a Field Configuration.

Traditionally, JIRA is configured with workflow transitions and screens – This allows you to map input through a series of steps and actions, controlling data with a series of conditions, validators, and post-functions. Lately, the common configuration is simple workflow with full Edit permissions. With this configuration, you have little option to control data input.

Script Runner Behaviors, as Nic also suggests, allows you to perform client-side validation on transition screens. This is one possible solution.

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 2, 2016

You can use Behaviours to do client side validation on edit if you need.  (I mention client side because it can be completely bypassed by REST or server stuff)

Roberto Saltini October 6, 2016

As far as I am aware, behaviours can only be used in a Transition Screens. Am I correct?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 6, 2016

No, it can be used on edit and create too.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events