Script Runner : verify values specified by users on validator of create transition

Christophe Leite September 17, 2013

Hi all,

On my issue screen creation, when I click on the create button, transition Create is run.

I would like to specify some rules in the validator's part of this transition.

In my case, I have :

- a listbox (called Type) where I must choose between the following values : Project, GPA, Versioning Service, DBA

- a listbox (called Project) containing a list of available projects

- a textbox (called RP Code)

I would like to control the following :

If Type.value="Project" then

  • listbox Project must be specified
  • textbox RP Code must be specified too

End if

If we choose the others values of Project listbox (GPA, Versioning Service or DBA), listbox Project is not mandatory as textbox RP Code.

I think I will have to use cfValues['Project'], cfValues['RP Code'] and cfValues['Type'], but I don't know how.

Thanks a lot.

Christophe

4 answers

1 accepted

1 vote
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.
September 17, 2013

The condition should be something like:

cfValues['Type'].value != 'Project' || (cfValues['RP Code'] && cfValues['Project'])

ie, either the type is not project, or both other fields must have values. Test in Admin -> Built-in Scripts -> Condition Tester.

Henning Tietgens
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 17, 2013

There is one ] missing at the end of Jamies condition, befor the ).

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

Thanks Henning, fixed it.

Christophe Leite September 17, 2013

Thank you but it does not work unfortunately...

'Type' is a simple list component ... may be cfValues['Type'].value is not good to obtain its value ?

Christophe Leite September 17, 2013

For the moment, I am just testing cfValues['Type'].value == "Project" ... but it still does not work :-(

Henning Tietgens
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 17, 2013

If you have configurable options for a custom field cfValues[] contains an Option object where you have to use getValue() to get the actual string value of the selected option. So cfValues['Type'].value should get you the text of the selected option.

Did you try the first and second part of the condition separatly in the condition tester mentioned by Jamie?

Henning Tietgens
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 17, 2013

Is Type a custom field? Or is it the issue type system field? If you want to access the issue type you have to write

issue.issueTypeObject.name == "Project"

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.
September 17, 2013
0 votes
Saleem Alikhan November 5, 2013

Hi Jamie,

After trying to create a new big of sample code to demonstrate the problem to you, it seemed to wanted to work. I've tested it locally on my JIRA environment as well as on our Dev/Test environments so the code works great.

Some code to add in the validator of the create transition that might help others debug which is a combination of the above suggestions.

Thanks again!

saleem

import org.apache.log4j.Category

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")

log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "_________________________"
log.debug "IssueKey : " + issue.getKey()
log.debug "Issue : " + issue
log.debug "Description : " + issue.getDescription()
log.debug "Summary : " + issue.getSummary()
log.debug "CustomValsArray: " + cfValues
log.debug "*** END ***"
log.debug ""
log.debug ""

0 votes
Saleem Alikhan November 4, 2013

Many thanks Jamie, I'll post up a new question with a proper example soon.

cheers!

0 votes
Saleem Alikhan October 29, 2013

Hi Jamie et all,

I was wondering if there was anything special that needs to be done to view the values on the Create Issue screen inside of a Groovy validator. I have tried the above stated "cfValues" array, but I don't see anything in the validator code. This problem only happens when creating a non-subtask issue (story/bug/epic).

Any thoughts would be appreciated.

thanks!

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.
November 2, 2013

No, there is nothing specific here...

Not sure what this means:

"but I don't see anything in the validator code"

Probably best to post a new question with a concrete example of what doesn't work.


Suggest an answer

Log in or Sign up to answer