Limit Fix Version to one value

Alex Christensen
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 11, 2016

I am trying to limit the user's input into Fix Version/s to only one value. I can do this easily in a validator as part of the workflow using ScriptRunner, but I'm having a lot of trouble even coming up with an idea of how to do this using a script listener in case a user makes inline changes or edits to an issue. Is there a way I can make the Fix Version/s field have a validator as a script listener?

2 answers

1 accepted

1 vote
Answer accepted
MichałS
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 11, 2016

We did this some time ago with a listener. 

When the user provided a second fixVersion then the older one was deleted and a comment was created to inform the user about it.

It does not work exactly as a validator but more like a post update rutine. The good part is that you always have the change history of the issue so it is easy to go back.

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 11, 2016

That sounds like a pretty good workaround.

Alex Christensen
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 11, 2016

Appreciate the feedback from both of you - this seems like the best option for us, probably. Thanks for your help!

Marc Minten _EVS_
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 11, 2016

Hmm, I am surprised about the answers, or do I miss something? Using a Listener to do input validation seems strange to me...With the behavior module of scriptrunner this is very easy to do (we did), and it works very well. When the user tries to add 2 values in the version field, an error message is shown below the field and the user can't save.

The only "disadvantage" is that in-line editing for the version field is blocked as behaviors do not work in in-line editing mode (blocking the in-line editing for fields with behaviors is an acceptable limitation for us)

Alex Christensen
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 12, 2016

Thanks, Marc. I've been messing with the Behaviors plugin this morning and was able to get this script so far.

import com.atlassian.jira.project.version.Version


def fixVersions = getFieldById(getFieldChanged())
Collection<Version> fixVersionsValue = (Collection<Version>) fixVersions.getValue()


if (fixVersionsValue.size() > 1) {
    fixVersions.setError("Fix Version/s can only be one value.")
}
else {
    fixVersions.clearError()
}

However, even though there is an error set on this field, I'm still able to save and submit the Edit form. Am I missing something from the script here?

Marc Minten _EVS_
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 12, 2016

Interesting smile

What version of scriptrunner do you use ? We had the same issue (bug?) when migrating to JIRA 7.1.7 and Scriptrunner 4.3.5.

I got a patch version Scriptrunner 4.3.7-m3 from Adaptavist (Jamie) that solved this problem. I did not validate (yet, nor install) if the "official" versions 4.3.8 or 4.3.9 include this fix...

Marc Minten _EVS_
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 12, 2016

...I think you also have to add the setValid method on the form field:

if (fixVersionsValue.size() > 1) {
	fixVersions.setValid(false)
    fixVersions.setError("Fix Version/s can only be one value.")
}
else {
	fixVersions.setValid(true)
    fixVersions.clearError()
}
Alex Christensen
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 12, 2016

Just tried adding the setValid method - no luck, unfortunately. I'm still able to save the Edit form. Is there documentation that covers all of the methods I can use on a FormField object? I noticed the setValid method isn't in the Quick Reference section when creating an inline script, so I'm curious to know if there are other methods I don't know about that I can use. Can't seem to find it in the Adaptavist documentation for the plugin.

As for the versions we're on - for JIRA, we haven't been able to upgrade to JIRA 7 yet, so we're still on 6.4.6 and ScriptRunner is version 4.1.3.16.

Alex Christensen
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 12, 2016

After some more trial and error, I figured out that if I set the field to be optional in the Behavior configurations, this validation script works correctly now. I can add some else block to the script to set the field as required if there are no values in the field at all.

Thanks for your help!

Shob June 2, 2020

Hi,

This was extremely helpful!!

If i have a validator that is supposed to make sure the field is not empty when status is to be moved to "in progress" 

will that script affect that? will it still work?

Alex Christensen
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 3, 2020

@Shob - this particular script does not take into account if the field is empty. Instead of implementing this on the behaviour, I would personally opt for implementing a workflow validator that makes the Fix Version/s field required and have a transition screen that pops up during the workflow transition to "In Progress" that includes this Fix Version field. Combined with the behaviour script, this should fulfill your needs.

Shob June 9, 2020

I will try to do that.

Thank you very very much for the assistance.

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 11, 2016

ScriptRunner does not offer "edit validators"... you might try this: http://www.j-tricks.com/tutorials/one-fixversion-please (I have not personally tried it so can't vouch for whether it works with the latest version).

Suggest an answer

Log in or Sign up to answer