Hi,
I want to restrict the Fix Version value to a few specific patterns (only numbers) so the users won't be able to insert any value they want. For example:
x.x.xx
x.x.xx.xxx
The "regular expression check" validator doesn't help because fix version doesn't show in the fields list.
Is there a way to use groovy script for that purpose?
Thanks,
Noga.
Community moderators have prevented the ability to post new answers.
The tricky part is newly created versions because they are not created yet so are not proper Version objects.
You should use the following behaviours script on the Fix Version/s field:
import com.atlassian.jira.project.version.Version import com.onresolve.jira.groovy.user.FieldBehaviours import groovy.transform.BaseScript @BaseScript FieldBehaviours fieldBehaviours def formField = getFieldById(getFieldChanged()) def fixVersions = formField.getValue() as List<Version> // This handles newly created versions by the user (single and multiple) def rawValues = [] rawValues.addAll(formField.getRawValue()) def createdFixVersions = rawValues.findAll { version -> version.startsWith("nv_") }.collect { version -> version.replaceAll("nv_", "") } def allFixVersions = fixVersions*.name + createdFixVersions as List<String> if (allFixVersions && ! allFixVersions.every { it ==~ /^(\d+\.)?(\d+\.)?(\*|\d+)$/ }) { formField.setError("Fix version invalid!") } else { // no versions or fix version is valid formField.clearError() }
The regex matches the following version format from: http://stackoverflow.com/questions/82064/a-regex-for-version-number-parsing
You will need to adjust it for your use case. This will help you get started.
Hope this helps,
Adam
Does "nv_" is the start of any new version? or I need to adjust it too?
def createdFixVersions = formField.getRawValue().findAll { version -> version.startsWith("nv_") }.collect { version -> version.replaceAll("nv_", "") }
Noga.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Its the start of any new version that the user enters through the create new version in the dropdown. These are not actually created till you submit the issue form, so are prefixed with "nv_".
The code I gave you should work for all these cases. You just to adjust the regular expression.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Adam,
It is still not working..
I changed the regex and used this expression:
/^([0-9]{1,2}+)\.([0-9]{1,2}+)\.([0-9]{1,2}+)\.([0-9]{0,4})$/
I don't get the error message ("Fix version invalid!") when I add a new unmatched fix version and I can submit the changes.
When I enter the edit screen in the second time, I get the error and it prevent me to click "edit" and update the issue.
Attached screenshots
.first time - edit screen.PNGsecond time - edit screen.PNG
I need it to display the error when I try changing the fix version on the first time.
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is this JIRA 6 or 7? For some reason I only got an email just now that you had added this comment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Noga, I have updated the script in my answer. For some reason my script didn't handle single versions only multiples for the new versions. Hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem, glad we got there in the end.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should add the script on the fix version field and then replace the second line with:
def fixVersionField = getFieldById(getFieldChanged());
That should work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Adam,
I tried using the behaviours and added a serverside script on Fix Version field.
But it doesn't do anything.
import com.atlassian.jira.project.version.Version; def FixVersionField = getFieldById("fixVersion"); def versions = FixVersionField.getValue() as List<Version> versions.any {it.getName().matches(/(\d{1,2})\.\d\.\d{2,2}\.\d{0,4}\)/)}
Is this how it should look ?
Noga.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Adam,
I want to restrict the format of fix version always - during a transition , in edit screen and when in every other option you have to add a new version.
Noga.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A quick google yielded: https://answers.atlassian.com/questions/325514
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is this for when you edit an issue, you want to restrict the fix version added? Rather than editing on a screen during a transition? Once I have more information I will give an example but behaviours will be useful for this: https://scriptrunner.adaptavist.com/4.3.2/jira/behaviours-overview.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.