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

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

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 Community Champion Sep 17, 2013

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

Thanks Henning, fixed it.

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 ?

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

Henning Tietgens Community Champion Sep 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 Community Champion Sep 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"

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!

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.


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

cheers!

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 ""

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Meet the AUG leaders of Northern Virginia

@Rachel Wright (Jira Genie), @Billy Poggi (AUG NOVA, DC), and @Dana Jansen (Confluence Queen) are just some of the folks that lead one of the world's most active Atlassian User Group (AUG)....

121 views 4 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you