Forums

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

Validate several different values within the same field (Story Points) on CREATION of an issue

Marcus Lyne
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
May 25, 2021

Hi all, 

I am an administrator and have had a request come in asking for me to limit the values that can be selected for the 'Story Points' field. This is a request for one project though, so I cannot edit the field as this would affect all projects using the field. I am a 'Level 1' and therefore have very limited experience with scripting. After reviewing the validators, I am under the impression that the best way for me to achieve this is through the 'Script Validator [ScriptRunner]' and then via the 'Simple Scripted Validator' option. The issue I am having is I can't quite figure out the actual script to use. The options I need available are as follows: 0, 1, 3, 5, 8, 13 and 20. 

The version of Jira I am using is: Jira Software 8.5.8 

Would anybody be able to give me a hand with this? Would be hugely appreciated. 

Thank you! 

2 answers

1 accepted

2 votes
Answer accepted
Vikrant Yadav
Community Champion
May 25, 2021

@Marcus Lyne  you can use Scripted Regex validator in Workflow. For this you have to put below code :-

 cfValues['Field Name'] ==~ /^(2|4|5|6|10|18)$/

Vikrant Yadav
Community Champion
May 25, 2021

Validator 13 .PNG

Hope this screenshot helps you. 

0 votes
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.
May 25, 2021

Yep, this script is quite short and is probably the most common use case (checking a custom field value, not your specific case)

def customFieldName = "Story Points"
def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
assert customField: "Could not find custom field with name $customFieldName"

def value = issue.getCustomFieldValue(customField)

if (value == 1 || value == 3 ...) return true
return false

But, I think I'd want to be a bit sneakier - rather than clobber the user and return then to their transition screen to re-enter it, maybe automate a correction.  You could add a listener that does something like "If SP = 2 then set it to 3, if 4 or 6, set to 5, if 7-11 set it to 8, if 12-19, use 13, and if over 19, set it to 20".  Oh, and round it too, in case someone is completely missing the point of planning poker and taking a mean average of the cards shown in a hand.

I'd use a listener to do this because you can have those work on issue edits as well as transition (validators only check on transition, there's nothing that would stop someone editing an issue and changing the points to a hundred, twelvety or any other number)

Suggest an answer

Log in or Sign up to answer