Error in Groovy simple scripted Validator - JIRA 5.2

To validate issue subtype we have a simple scripted Validator.It was wrking fine in JIRA 4.2.But throws error in 5.2 .10 version.Can someme pls confirm if there is any syntax change is required?

cfValues['Issue sub-type'] == 'Enhancement' || cfValues['Issue sub-type'] == 'Defect' || cfValues['Issue sub-type'] == 'Role Change' || cfValues['Issue sub-type'] == 'New Development' || cfValues['Issue sub-type'] == 'Configuration Change'

2 answers

1 accepted

1 votes
Henning Tietgens Community Champion Aug 05, 2013

If the custom field is a select field you will now get an Option object instead of a string. Try cfValues['Issue sub-type'].getValue() instead of cfValues['Issue sub-type']

Thanks Much Henning.It works now

Can you pls tell if there is any change required in the below script?

def e = customFieldManager.getCustomFieldObjectByName('Level of Effort')
def i = customFieldManager.getCustomFieldObjectByName('Impact on functionality')
issue.getCustomFieldValue(e) != null && issue.getCustomFieldValue(i) != null

I have this scripted validator for "Generate Checklist" transition.Getting [InvalidInputException: [Error map: [{}]] [Error list: [[The Level of Effort and Impact on functionality fields must be completed prior to generating the checklist.]]]

This was working good in 4.2 ,Could you please help?

Thanks

Henning Tietgens Community Champion Aug 05, 2013

Looks good for me.

Hi

My scripted validtaor gets failed (Message given in
Error Message field is getting diaplyed)when I issue the code as below

def e = customFieldManager.getCustomFieldObjectByName('Level of Effort')
def i = customFieldManager.getCustomFieldObjectByName('Impact on functionality')
issue.getCustomFieldValue(e) !=null || issue.getCustomFieldValue(i) !=null

Where as it gets thru when I modified the condtion for ==(as below)

def e = customFieldManager.getCustomFieldObjectByName('Level of Effort')
def i = customFieldManager.getCustomFieldObjectByName('Impact on functionality')
issue.getCustomFieldValue(e) ==null || issue.getCustomFieldValue(i) ==null

But My requiremet is !=null should get pass.

So here the problem is def e def i are getting interpretted as null.. can you please help to pass this validator?

Henning Tietgens Community Champion Aug 07, 2013

What's the error message? Are the names of the CFs correct? Try to debug with log.debug "" messages what the values of e and i are.

I got it fixed henning..Actually these fields needs to be set via the JIRA Ticket.Since Iam new to JIRA .. I didnt understand the basics.

thanks much for your reposnse.

Hi Henning

I get the below error in Script14.groovy.(there is no such groovy in the script path)

2013-08-12 04:14:58,985 http-6443-17 ERROR wb391456 254x2016x17 ugih9r 10.185.5.137,10.185.160.15 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyCustomField] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:Script14.groovy: 1: expecting '(', found 'Issue' @ line 1, column 4. if Issue Classification = "System Change" ^ 1 error javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:Script14.groovy: 1: expecting '(', found 'Issue' @ line 1, column 4. if Issue Classification = "System Change" ^ 1 error at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:216) at javax.script.ScriptEngine$eval.call(Unknown Source) at com.onresolve.jira.groovy.GroovyCustomField.getValueFromIssue(GroovyCustomField.groovy:150) at com.atlassian.jira.issue.fields.CustomFieldImpl.getValue(CustomFieldImpl.java:384)

Can u pls tell the cause for this kind of error?

Thanks

Henning Tietgens Community Champion Aug 11, 2013

That's an error from the code of a scripted field. There must be a line like

if Issue Classification ...

The condition of an if statement has to be in ().

Hi Henning,

Below is the Multi Checklist field script Validator.

// set properties default value if missing
def cp = customFieldManager.getCustomFieldObjectByName('Checklist Properties')
def properties = issue.getCustomFieldValue(cp)
properties?.contains("Default checklist items for Overall Impact level")

Here always it gets evaluated to false and I get the error message I defined.

Pls help

Henning Tietgens Community Champion Aug 12, 2013

Please try def properties = issue.getCustomFieldValue(cp)?.value, because it's an Option object for fields with multiple possible values.

The error message must be from another script.... do you have other scripts?

Still getting the same error(here error I meant is the error defined by me to be thrown when the condition is not satisfied ,But the checkbox of "Default checklist items for Overall Impact level" is checked already in the Checklist description )

// set properties default value if missing
def cp = customFieldManager.getCustomFieldObjectByName('Checklist Properties')
def properties = issue.getCustomFieldValue(cp))?.value
properties?.contains("Default checklist items for Overall Impact level")

I get this error becoz the variable properties is not reading the value as it expects.

Kindly help

Error at log :

java.lang.ClassCastException: java.lang.String cannot be cast to com.atlassian.jira.issue.customfields.option.Option

Henning Tietgens Community Champion Aug 12, 2013

There is an ")" to much before the question mark in the def properties row.

Sorry ,that was a typo error.) is not there in my script validator.

// set properties default value if missing
def cp = customFieldManager.getCustomFieldObjectByName('Checklist Properties')
def properties = issue.getCustomFieldValue(cp)?.value
properties?.contains("Default checklist items for Overall Impact level")

Henning Tietgens Community Champion Aug 13, 2013

Please try this and post the log.

// set properties default value if missing
def cp = customFieldManager.getCustomFieldObjectByName('Checklist Properties')
log.error "customFieldManager: $customFieldManager"
log.error "cp: $cp"
def properties = issue.getCustomFieldValue(cp)?.value
log.error "value: ${issue.getCustomFieldValue(cp)}"
log.error "value.class.name: ${issue.getCustomFieldValue(cp)?.class?.name}"
log.error "value.value: ${issue.getCustomFieldValue(cp)?.value}"
log.error "properties: $properties"
log.error "properties.class.name: ${properties?.class?.name}"
properties?.contains("Default checklist items for Overall Impact level")

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,850 views 12 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot