Forums

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

How to write a groovy validation simple script runner checking components against a regular expression

Sheral Hewes
Contributor
December 18, 2014

Using JIRA 5.2.11

I want to validate that when a issue type "Library" is selected, only components that start with "Library" can be selected.

I have to components named "Library - model" and "Library - service"

My validation error displays no matter whether the component is something else or one of the Library ones above.

Please help.  Code below.

if (issue.issueTypeObject.name == "Library"){
    if(issue.components*.name ==~ /Library.*/){
        return true;
    } else {
        return false;
    }
} else {
    return true;
}

1 answer

1 accepted

0 votes
Answer accepted
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.
December 18, 2014

You're doing a pattern match on a list, which won't work. You want something like (untested):

if (issue.issueTypeObject.name == "Library"){
    issue.componentObjects*.name.every { it ==~ /Library.*/ }
} else {
    true;
}
Sheral Hewes
Contributor
December 19, 2014

Worked Thanks!

Raj Kusumba
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!
August 13, 2020

Hi @JamieA 

I have similar requirement but the List names has a dot.

Like Library.model and Library.service

what is the pattern match of a dot ?

 

Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events