How to Handle FixVersion/s logic in Server Side ScriptRunner Behavior?

Benjamin Dains December 28, 2020

INTRO

My brain feels like a jumbled mess now that I tried to do this, so I thought, I'll get some help!

CASE:
Our organization decided to limit the FixVersion/s field to only 1, and to make the field required... so I set out on that journey. I used the workflow transitions to check the number of FixVersion/s using a scripted validator, and I used the behavior's functionality to make it a required field, and so far that has worked. 

PROBLEMS:
(1) People can still go to the edit screen, adjust the FixVersion count, and nothing will stop them from updating it because that logic only runs on a workflow transition.

(2) Issues that had multiple FixVersion/s before I made the changes above are still able to use the quick transition buttons move an issue through it's status, and nothing this behavior even though it's a required field, and there is a validator script.

(3) The server side validation for behaviors seems to be very limited as to what you can do with .getValue()... I'm not able to use .size() or .length() (that I know of) to check the number of FixVersion/s. 

CODE:

I put some of the server side code I tried to write to run this check, but I don't think I made it very far.

def fixVersionsField = getFieldByName("fixVersions")

if (fixVersionsField.getValue() == null || fixVersionsField.getValue() == "" ){
fixVersionsField.setError("Version must be populated.")
} else if () {
// I deleted this, but thought someone here might be able to help me.
}  

 

1 answer

1 accepted

1 vote
Answer accepted
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 1, 2021

Hi @Benjamin Dains,

 

You can try out below code, I've added this to server-side script for fix versions field and tested with my sandbox 

def fVersions = getFieldById("fixVersions")
def versions = fVersions.formValue as String
def vList = versions.split(',') as List

if(vList.size() > 1){
fVersions.setError("You should not select more than one fix version...!!")
}else{
fVersions.clearError()

 

Hope this helps

 

BR,

Leo 

Benjamin Dains January 15, 2021

Hi Leo, thanks a bunch, sorry for the delay, I'll give it a go soon.

We have been really busy with a deploy that is going live tonight, so early next week I'll probably try this. 

My biggest problem I had was trying to figure out how to get the fixVersion to count.

Benjamin Dains January 15, 2021

@Leo I went ahead and tried it this morning since I already have a ScriptRunner behavior setup, and this worked perfectly. Thanks for the help!!!

Suggest an answer

Log in or Sign up to answer