Valiade (custom) field

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
Accepted answer

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? 

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.

>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.

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
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

351 views 0 1
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you