script validator - fixversion

arild marthinussen September 24, 2013

Hi, I'm trying to add a validator on an existing transition.

"If the Fixversion field has no value, user should get a message "fix version must have a value", and is not allowed to transmit untill fixversion has a value"

I've tried this with custom fields - cfvalues['somefield'] - and this works for custum fields, but not for the field fixversion

Any ideas ?

6 answers

1 accepted

2 votes
Answer accepted
RambanamP
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.
September 24, 2013

you can try something like this

def fixVersion= issue.getFixVersions();
 if (fixVersion == null) {
//throw error message here
}

2 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 10, 2013

You can use the "simple scripted validator" where the condition should just be:

issue.fixVersions

Let groovy worry about whether it's null or an empty collection or whatever.

0 votes
Mizan
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 10, 2013

There is a field required validator provided by suite utilities plugin which you can use.

0 votes
arild marthinussen October 10, 2013
def fixVersion= issue.getFixVersions()

This resolved my problem

Thank's :-)

0 votes
Batuhan Kandiran September 24, 2013

Hi Arild,

You must add your .groovy script as validator for your transition.

You can use these codes as groovy workflow validator script

import java.util.ArrayList;
import java.util.Collection;
import com.atlassian.jira.config.ConstantsManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.project.version.Version;
import com.opensymphony.workflow.InvalidInputException;

Collection<Version> fixVersions = new ArrayList<Version>();
	fixVersions = issue.getFixVersions();
	if(fixVersions.size() == 0)
		invalidInputException = new InvalidInputException("fixVersions","Fix Versions field can not be empty.");

0 votes
arild marthinussen September 24, 2013

Hi, tried this - error message is thrown every time...even if fixversion has a value.

But I tried only:

def fixVersion= issue.getFixVersions()

This resolved my problem

Thank's :-)

RambanamP
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.
September 24, 2013

glad to hear it worked!!

Suggest an answer

Log in or Sign up to answer