Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Valiade (custom) field

Andreas Meier April 26, 2017

I have to check, if a field contains a 4-digit number (Project-ID). As this seems not to be possible out of the box, I try to achieve this with a custom field and script-runner. I also found an interesting page https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/validators/simple-scripted-validators.html, but I nowhere in Jira (Software, Server) find this view.

Can please someone lead me to this view?

Is there a better way to validate fields?

1 answer

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
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.
April 26, 2017

Have you got Script Runner installed?

If you have, then try going back to the workflow and add a validator, then check the list of types of validator do you get the scripted validator option on the list? 

Andreas Meier April 26, 2017

Hi Nic

Thanks for help.

Script Runner is installed.


I open <JIRA Administration><Issues><Workflow> and select the workflow of one project. On a transition I then can add a validator. If I select 'script validator' and 'Simple scipted validator' there is the missing view :)


Do I have to do this for every transition in every single project? Is this only checked, if there is a transition (and not on 'Save')?


and last: 4 digits numeric-Test - which language is used? would this work?
cfValues['field'].lenth() == 4 & isInteger.(cfValues['field'].value)


Sorry, I need realy basic support.

Nic Brough -Adaptavist-
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.
April 26, 2017

>Do I have to do this for every transition in every single project?

Transitions are not part of a project directly, they are part of a workflow (they can be used multiple times in a workflow though).  If a workflow is used by several projects, then you will affect all of them just by changing that single workflow, but if your projects all use different workflows, then yes, you're going to have to go into each workflow to edit the transitions that need changing.

>Is this only checked, if there is a transition (and not on 'Save')?

I don't understand the question.  A validator runs when the transition it belongs to is committed to by a user, if that helps explain though.

>4 digits numeric-Test - which language is used?

Groovy and/or java are easiest to use in script runner

>would this work?

I think so, barring the spelling mistake.  I've not used isInteger like that before, but it looks right.

Andreas Meier April 27, 2017

It's working :)

I understand the meachanism and I'v learned a lot - but it's not done.

The validation should be done on 'every' update (save) to the issue and not only on workflow-transitions.

Back to my second question >Is there a better way to validate fields?


Additional Infos:

The defined Error Message is only shown, if no Field is defined and it's always a PopUp - no need to handle in the moment.

Working Condition for Simple scripted Validator:

String myPJ = cfValues['PJ-ID'];
if (myPJ.length() == 4 && myPJ.isInteger()) {
    1 == 1;
}

I'm pretty sure there are better possibilities, but it works fine.

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events